android - How to get the reference of the built graph using Dagger2 DI? -
i have peractivity component. build graph in oncreate of activity this:
mactivitycomponent = daggeractivitycomponent.builder() .appcomponent(browserapp.getappcomponent()) .activitymodule(new activitymodule()) .build();
it pretty straight forward reference of mactivitycomponent
in fragments. can use it:
((mainactivity)getactivity()).getactivitycomponent();
the problem arises in other classes. let's have webview doesn't have method getactivity()
. how should reference mactivitycomponent
? if pass reference in constructor, doesn't defeat purpose of using dependency injection? , cannot make static, because won't "peractivity" anymore, 1 , same activities.
Comments
Post a Comment