1 回答
TA贡献1825条经验 获得超6个赞
经过一整天的麻烦,我找到了适合我的情况的解决方案。所描述的所有模块 (, ) 都需要在我的应用程序模块中使用。Configuration_ModuleLocalisation_Module
因此,对于调用,我删除了所有组件依赖项。@ApplicationScope@ModuleApplicationModule
应用程序组件
@Component(modules = [ApplicationModule::class])
@ApplicationScope
abstract class ApplicationComponent {
abstract fun inject(mainActivity: MainActivity)
}
应用模块
@Module
class ApplicationModule(private val localisationComponent: LocalisationComponent,
private val configurationComponent: ConfigurationComponent) {
@Provides
@ApplicationScope
fun providesLocalisationRepository(): LocalisationRepository {
return localisationComponent.localisationRepository() // Provided by Localisation module with Dagger
}
@Provides
@ApplicationScope
fun providesConfigurationRepository(): ConfigurationRepository {
return configurationComponent.configurationRepository() // Provided by Configuration module with Dagger
}
}
最后是我的主要应用程序
class MainApplication : Application() {
lateinit var applicationComponent: ApplicationComponent
override fun onCreate() {
super.onCreate()
this.registerDependencies()
}
private fun registerDependencies() {
val coreModule = CoreModule(applicationContext)
val applicationModule = ApplicationModule(LocalisationModule(coreModule).localisationComponent,
ConfigurationModule(coreModule).configurationComponent)
applicationComponent = DaggerApplicationComponent.builder()
.applicationModule(applicationModule)
.build()
}
}
我指出,一切都像一个魅力。
添加回答
举报