Skip to content

Instantly share code, notes, and snippets.

@mrmike
Last active July 14, 2017 16:12
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 mrmike/e5d7afd892bee3ce1b6305a2346deea4 to your computer and use it in GitHub Desktop.
Save mrmike/e5d7afd892bee3ce1b6305a2346deea4 to your computer and use it in GitHub Desktop.
Replacing modules with dagger component builder
# 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