如何将组件从应用程序返回到模块?

问题描述

试图理解以下example并做类似的事情。

在我的应用程序中有一个模块,我想在其中使用Dagger。 为此,我需要一个Application类,在其中初始化并存储sh run.sh 123 555

从文档来看,我需要使用模块中的组件创建接口:

AppComponent

然后,我将为我的Application类实现此接口:

interface PasscodeSetupComponentProvider {
    fun providePasscodeSetupComponent(): PasscodeComponent
}

但是从文档中的示例来看,我不知道界面open class FenturyApplication : PasscodeSetupComponentProvider { lateinit var appComponent: AppComponent override fun onCreate() { super.onCreate() appComponent = DaggerAppComponent.builder() .appModule(AppModule(applicationContext)) .build() } override fun providePasscodeSetupComponent(): PasscodeComponent { return appComponent.passcodeComponent } } Appcomponent应该是什么。

在示例中,它看起来像这样:

passcodeComponent

我在AppComponent中添加了以下代码:

class MyApplication: Application(),LoginComponentProvider {
  // Reference to the application graph that is used across the whole app
  val appComponent = DaggerApplicationComponent.create()

  override fun provideLoginComponent(): LoginComponent {
    return appComponent.loginComponent().create()
  }
}

如果我理解正确,那么在我模块的片段中,我可以编写以下内容:

@Component(modules = [AppModule::class])
@Singleton
interface AppComponent {
    val applicationContext: Context
    fun passcodeComponent(): PasscodeComponent
}

之后,我希望我可以在模块中使用匕首。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)