You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a @Binds is declared in Component, and the provision for the source of the bind is given in a subcomponent, Dagger is unable to fulfill the binding, even if it's only used from the subcomponent.
For example:
@dagger.Component(modules = BindingModule.class)
interface Component {
OurSubcomponent subcomponent();
}
@Module
interface BindingModule {
// note: Thing is an interface which ThingImpl extends.
@Binds
Thing thing(ThingImpl thingImpl);
}
@dagger.Subcomponent(modules = {ThingModule.class})
interface OurSubcomponent {
Thing thing();
}
@Module
static class ThingModule {
@Provides
ThingImpl thingImpl() {
return new ThingImpl();
}
}
This results in the following error:
interface Component {
^
com.deviange.daggerrebind.ThingImpl is injected at
com.deviange.daggerrebind.DaggerComponent.BindingModule.thing(thingImpl)
com.deviange.daggerrebind.Thing is provided at
com.deviange.daggerrebind.DaggerComponent.OurSubcomponent.thing() [com.deviange.daggerrebind.DaggerComponent.Component → com.deviange.daggerrebind.DaggerComponent.OurSubcomponent]
I also only chanced upon this solution through sheer luck. It'd be much more intuitive if a @Binds declared at the component level could be fulfilled at the subcomponent level without re-including the Binds.
For context: the reason why I came across this is because AssistedInject provides a convenience module that has all the bindings for the factories in a single module.
The text was updated successfully, but these errors were encountered:
I think this is working as intended, though I can understand why you'd want it to work this way. I think it would cause a lot of confusion since you could have an @Binds at a component level that couldn't actually be used from that component.
On Dagger 2.27.
If a
@Binds
is declared inComponent
, and the provision for the source of the bind is given in a subcomponent, Dagger is unable to fulfill the binding, even if it's only used from the subcomponent.For example:
This results in the following error:
One way around this is to re-include the binding module in the subcomponent. However, I'm not sure if this is even intended, as the documentation seems to suggest that repeating modules will just reuse the parent Component module.
I also only chanced upon this solution through sheer luck. It'd be much more intuitive if a
@Binds
declared at the component level could be fulfilled at the subcomponent level without re-including theBinds
.For context: the reason why I came across this is because AssistedInject provides a convenience module that has all the bindings for the factories in a single module.
The text was updated successfully, but these errors were encountered: