I am trying to set up a project in which I have two modules common-lib
and app
.
The lib module has its own Dagger component and modules, and it's supposed to be flavor agnostic.
Now, part of it depends on flavor specific resource values declared in the module app
, so I tried abstracting the component through an interface and override its implementation in the module app
.
Dagger module declare in common-lib
gradle module, satisfying dependencies with NoOp implementations.
@Module
public class NetworkConfigModule {
@Provides
@Singleton
HeaderParams providesHeaderParams(NoOpHeaderParams noOpHeaderParams){
return noOpHeaderParams;
}
@Provides
@Singleton
AppHostsProvider providesAppHostsProvider(NoOpAppHostsProvider noOpAppHostsProvider){
return noOpAppHostsProvider;
}
}
Dagger module declare in app
gradle module, satisfying dependencies with the actual implementation.
@Module
public class NetworkConfigModule {
@Provides
@ApplicationScope
HeaderParams providesHeaderParams(KaufdaHeaderParams kaufdaHeaderParams){
return kaufdaHeaderParams;
}
@Provides
@ApplicationScope
AppHostsProvider providesAppHostsProvider(KaufdaAppHostsProvider implementation){
return implementation;
}
}
This doesn't work, because Dagger just doesn't override the Module class, but that's somehow expected.
My question is, how I can set up my Dagger modules so I can use HeaderParams
and AppHostsProvider
interfaces in common-lib
, but I inject their implementations in app
.