android - Dagger 2: Inject child class based on logic -


using dagger 2 in android mvp pattern, , struggling little concepts.

let's have presenter dashboardpresenter, injecting when need in activity or other presenters, using:

@inject dashboardpresenter presenter; 

or in constructor of other presenters:

@inject public accountpresenter(dashboardpresenter presenter) {     //init } 

now i'm not sure how works, want following:

let's create basedashboardpresenter parent

and create 2 children it: normaldashboardpresenter , prodashboardpresenter both extends it.

when want use in activity or presenter, inject base presenter calling

@inject basedashboardpresenter presenter; 

and override @inject behavior, inject 1 of children based on boolean. this:

//in basedashboardpresenter  override inject() {     if(utility.checkifuserispro()) {         inject prodashboardpresenter();     } else {         inject normaldashboardpresenter();     }  } 

so activity call abstract methods in base class, , difference child injected.

is possible? happy provide more clarification if needed.

to this, should add in module this:

@provides public basedashboardpresenter providedashboardpresenter(otherpresenter presenter) {     if (utility.checkifuserispro()) {         return new prodashboardpresenter();     } else {         return new normaldashboardpresenter(presenter);     } } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -