Skip to content

Instantly share code, notes, and snippets.

Created September 19, 2014 05:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jvergeldedios/a5b4b83f574e330c51cf to your computer and use it in GitHub Desktop.
Simple example of Dagger in Android
public class MyApp extends Application {
private ObjectGraph objectGraph;
public void onCreate() {
objectGraph = ObjectGraph.create(new AppModule(this));
public static void inject(Context context, Object toInject) {
MyApp app = (MyApp)context.getApplicationContext();
public static void inject(Context context) {
inject(context, context);
injects = {
public class AppModule {
private Context context;
public AppModule(Context context) {
this.context = context;
@Singleton @Provides
GSHTTPClient provideGSHTTPClient() {
return new GSHTTPClient(context);
public class FooActivity extends Activity {
GSHTTPLib httpLib;
public void onCreate() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment