我正在使用 Koin 将 Activity 注入演示者,但现有的 Activity 实例没有传递给演示者。而是创建一个新的。我错过了什么?
val mainModule = module {
single<IStartupActivity> { StartupActivity() }
factory<IStartupPresenter> { StartupPresenter(get()) }
}
class StartupPresenter(val view: IStartupActivity): IStartupPresenter {
}
class StartupActivity : Activity(), IStartupActivity {
val presenter: IStartupPresenter by inject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
I/KOIN: +-- 'inf.ecg.presenter.interfaces.IStartupPresenter'
D/KOIN: |-- [Factory [name='IStartupPresenter',class='inf.ecg.presenter.interfaces.IStartupPresenter']]
I/KOIN: | +-- 'inf.ecg.view.interfaces.IStartupActivity'
D/KOIN: | |-- [Single [name='IStartupActivity',class='inf.ecg.view.interfaces.IStartupActivity']]
D/KOIN: | |-- inf.ecg.view.implementations.StartupActivity@4176160
I/KOIN: | \-- (*) Created
D/KOIN: | !-- [inf.ecg.view.interfaces.IStartupActivity] resolved in 4.378594 ms
D/KOIN: |-- inf.ecg.presenter.implementations.StartupPresenter@ddfe619
I/KOIN: \-- (*) Created
D/KOIN: !-- [inf.ecg.presenter.interfaces.IStartupPresenter] resolved in 18.235835 ms