我目前正在尝试从dagger-android迁移到Hilt。以前,我使用@Bind将片段和活动的实例绑定到相应的MVP View合约。有没有办法对Hilt做同样的事情?似乎无法注入特定的片段和活动?
答案 0 :(得分:0)
我们需要一些代码来给出正确的答案,但我认为您需要类似的东西
@InstallIn(ActivityComponent::class)
@Module
abstract class MyScreenModule {
@ActivityScoped
@Binds
abstract fun bindMyScreenFragment(impl: ScreenFragment): MyScreenContract.View
@ActivityScoped
@Binds
abstract fun bindMyScreenPresenter(impl: ScreenPresenter): MyScreenContract.Presenter
}
别忘了:
注意::请考虑是否应将Presenter绑定到Fragment生命周期。在这种情况下,presenter绑定应将其自己的模块标记为 @InstallIn(FragmentComponent :: class),绑定的作用域应为@FragmentScoped