Skip to content

Instantly share code, notes, and snippets.

@neilbantoc
Created October 19, 2015 08:43
Show Gist options
  • Save neilbantoc/30883b3ffa4f84b655e9 to your computer and use it in GitHub Desktop.
Save neilbantoc/30883b3ffa4f84b655e9 to your computer and use it in GitHub Desktop.
@PerApp
@Component(
modules = {
SampleAppModule.class,
DataModule.class,
NetworkModule.class
}
dependencies = {
OtherComponent.class
}
)
public interface SampleAppComponent {
public void inject(SomeActivity someActivity);
public void inject(SomeFragment someFragment);
public void inject(SomeOtherFragment someOtherFragment);
Application application();
Picasso picasso();
Gson gson();
OkHttpClient okHttpClient();
}
@Module
public class SampleAppModule {
static final String PREFS_DEFAULT = "myapp";
final SampleApp app;
public AppModule(SampleApp app) {
this.app = app;
}
@Provides @PerApp SampleApp provideSampleApp() {
return app;
}
@Provides @PerApp Application provideApplication(SampleApp app) {
return app;
}
@Provides @PerApp SharedPreferences provideSharedPrefs(Application app) {
return app.getSharedPreferences(PREFS_DEFAULT, Context.MODE_PRIVATE);
}
@Provides @PerApp Gson provideGson() {
return new Gson();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment