Skip to content

Instantly share code, notes, and snippets.

@Kursulla
Created February 5, 2017 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kursulla/b03433aa40b3303dbb395065c259ea67 to your computer and use it in GitHub Desktop.
Save Kursulla/b03433aa40b3303dbb395065c259ea67 to your computer and use it in GitHub Desktop.
Maybe a solution for variable provides
//Application
public class YourApplication extends Application {
private static SomeComponent component;
}
public static getComponent(Bundle bundle){
component = DaggerSomeComponent
.builder()
.someModule(new SomeModule(bundle))
.build();
}
//Module class
@Module
public class SomeModule{
Bundle bundle;
SomeModule(Bundle bundle){
this.bundle = bundle;
}
@Provides
SomeClassInterface prividesSomeClass() {
if(bundle.getString("some_attr") == SOMETHING_1){
return new SomeClassImplementation1();
}else if(bundle.getString("some_attr") == SOMETHING_2){
return new SomeClassImplementation2();
}
}
}
//SomeClassInterface implementations
public SomeClassImplementation1 implements SomeClassInterface{}
public SomeClassImplementation2 implements SomeClassInterface{}
//Injection place
public void onCreate(Bundle savedInstanceState){
YourApplication.getComponent(getIntent.getExtras()).inject(this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment