I'm doing a relativity simple implementation of Hilt. I've set it up and I can't seem to get around this error:
[Dagger/MissingBinding] @dagger.hilt.android.qualifiers.ApplicationContext android.content.Context cannot be provided without an @Provides-annotated method.
@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
Here is my code:
@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
}
I'm new to Hilt - any ideas?
I think the issue is happening because in InstallIn() you are passing a fragment component and you are annotating your dependency with singleton , as far as i know that singleton can be applied to ApplicationComponent , so try to change @Singleton annotation to @FragmentScoped Annotation
@Provides
@Singleton --> to @FragmentScoped
fun provideFeatureComponentManager(@ApplicationContext context: Context) : FeatureControlManager {
return FeatureControlManager.getInstance(context)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With