I am not quite sure how to solve this with dagger 2.
Lets assume we have ApplicationModule
that provides us ApplicationContext
then we have ApplicationComponent
that uses just this one module.
Then on top of it we have ActivityModule
and ActivityComponent
that has dependency on ApplicationComponent
.
ActivityComponent
is build just like
ApplicationComponent component = ((MyApplication) getApplication()).getComponent();
mComponent = Dagger_ActivityComponent.builder()
.applicationComponent(component)
.activityModule(new ActivityModule(this))
.build();
And then I inject my activity:
mComponent.inject(this);
Now I am able to use everything that is declared inside my ActivityModule
, however it is not possible for me to access ApplicationModule
.
So the question is how could that be achieved? So that when I build component that depends on another component I can still access module from the first one?
EDIT
I think I have found solutions, after rewatching Devoxx talk by Jake again, I have had to miss that out, whatever I want to use from another components module I have to provide in that component, for example I want to use Context from ApplicationModule
then inside ApplicationComponent
I have to state Context provideContext();
and it is going to be available. Pretty cool :)