Last active
July 14, 2017 16:12
-
-
Save mrmike/e5d7afd892bee3ce1b6305a2346deea4 to your computer and use it in GitHub Desktop.
Replacing modules with dagger component builder
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
# In App class | |
public void onCreate() { | |
applicationComponent = initializeAppComponentBuilder().build(); | |
applicationComponent.inject(this); | |
} | |
protected DaggerAppComponent.Builder initializeAppComponentBuilder() { | |
return DaggerAppComponent.builder() | |
.applicationModule(new ApplicationModule(this)) | |
.networkModule(new RealNetworkModule()) | |
.databaseModule(new DatabaseModule()) | |
.networkModule(new MockNetworkModule()) | |
.picassoModule(new PicassoModule()) | |
.androidModule(new AndroidModule()) | |
.etc(); | |
} | |
# And in test app you can replace only those modules that has to be replaced with fake ones | |
public class TestsApp extends App { | |
protected DaggerAppComponent.Builder initializeAppComponentBuilder() { | |
return super.initializeAppComponentBuilder() | |
.networkModule(new MockNetworkModule()); | |
// and the rest of "real" modules is already provided | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment