我正在尝试将演示者实例@Inject注入Controller对象(Conductor lib)。我无法将演示者作为参数传递,因为我的控制器是由系统创建的。我们开始:
@Module
class FormModule {
@Provides
internal fun provideFormInteractor(interactor: FormInteractorImp): FormBaseInteractor = interactor
@Provides
internal fun provideFormPresenter(presenter: FormPresenterImp<FormBaseView, FormBaseInteractor>)
: FormBasePresenter<FormBaseView, FormBaseInteractor> = presenter
}
@Singleton
@Component(modules = [FormModule::class, RepositoryModule::class, AppModule::class])
interface FormProvider : AndroidInjector<FormController> {
override fun inject(fragmentController: FormController)
@Component.Builder
abstract class Builder : AndroidInjector.Builder<FormController>()
}
在我的onCreate()on FormController
中,我确实注入了礼物
@Inject
internal lateinit var presenter: FormBasePresenter<FormBaseView, FormBaseInteractor>
init {
DaggerFormProvider.builder().build().inject(this)
}
当我运行这段代码时,我收到了以下消息:
java.lang.IllegalStateException: org.secfirst.umbrella.feature.form.view.FormController must be set
at org.secfirst.umbrella.feature.form.DaggerFormProvider$Builder.build(DaggerFormProvider.java:102)
at org.secfirst.umbrella.feature.form.DaggerFormProvider$Builder.build(DaggerFormProvider.java:81)
at org.secfirst.umbrella.feature.form.view.FormController.<init>(FormController.kt:22)