我正在做一个相对简单的Hilt实现。我已经设置好了,我似乎无法绕过这个错误:
如果没有@Provides注释的方法,则无法提供Dagger/MissingBinding @dagger.hilt.android.qualifiers.ApplicationContext android.content.Context。
@dagger.hilt.android.qualifiers.ApplicationContext android.content.Context is injected at
com.greendotcorp.core.managers.featurecontrol.app.FeatureControlManager(context, …)
com.greendotcorp.core.managers.featurecontrol.app.FeatureControlManager is injected at
com.greendotcorp.core.features.dashboard.GridDashboardFragment.featureControlManager
com.greendotcorp.core.features.dashboard.GridDashboardFragment is injected at
com.greendotcorp.core.utils_theme.ViewModelDependencyInjector.inject下面是我的代码:
@Singleton
@Component(modules = [ViewModelInjectorModule::class])
interface ViewModelDependencyInjector {
fun inject(fragment: GridDashboardFragment)
}
@InstallIn(FragmentComponent::class)
@Module
object DashboardModule {
@Provides
@Singleton
fun provideFeatureComponentManager(@ApplicationContext context: Context) : FeatureControlManager {
return FeatureControlManager.getInstance(context)
}
@AndroidEntryPoint
class GridDashboardFragment : BaseDetailFragment() {
@Inject lateinit var featureControlManager: FeatureControlManager
}我是希尔特的新手--有什么想法吗?
发布于 2020-08-15 10:19:45
我认为发生这个问题是因为在InstallIn()中传递了一个片段组件,并且使用单例注释了您的依赖项,就我所知,单例可以应用于ApplicationComponent,所以尝试将@Singleton注释更改为@FragmentScoped注释
@Provides
@Singleton --> to @FragmentScoped
fun provideFeatureComponentManager(@ApplicationContext context: Context) : FeatureControlManager {
return FeatureControlManager.getInstance(context)
}https://stackoverflow.com/questions/63421025
复制相似问题