使用匕首@ContributesAndroidInjector在其子组件中注入片段实例

时间:2020-06-12 04:06:54

标签: android kotlin dagger-2 dagger

我正在使用范围进行片段/活动注射。我使用@ContributesAndroidInjector为每个片段/活动定义了一些模块。

片段模块

@FragmentScope
@ContributesAndroidInjector(modules = [TestingModule::class])
abstract fun bindTestingScreenFragment(): TestingScreen

TestingModule

@Module(includes = [TestingModule.TestingAbstractModule::class])
class TestingModule {

    @Provides
    fun provideDefaultArgs(testingScreen: TestingScreen): Bundle? = testingScreen.arguments
}

我想将包注入片段范围内,所以无论我在TestingScreen片段范围内注入束,我都会得到TestingScreen参数。 我需要知道的是,在provideDefaultArgs中,我正在注入当前正在注入的屏幕,因此,如何在没有任何循环依赖的情况下注入该屏幕,以上代码可以正常工作而没有任何错误。有人对此有任何想法吗?

0 个答案:

没有答案