Created
February 5, 2017 14:32
-
-
Save Kursulla/b03433aa40b3303dbb395065c259ea67 to your computer and use it in GitHub Desktop.
Maybe a solution for variable provides
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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