Skip to content

Instantly share code, notes, and snippets.

@cgruber
Last active August 29, 2015 14:09
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 cgruber/5b3a4f10d88d04154e89 to your computer and use it in GitHub Desktop.
Save cgruber/5b3a4f10d88d04154e89 to your computer and use it in GitHub Desktop.
Component exporting to dependent components
interface SingletonsToExport {
SomeService someService();
OkHttpClient httpClient();
GooglePlayThingamabob playThingy();
}
@Singleton
@Component(...)
interface ApplicationComponent extends SingletonsToExport {
void inject(MyApplication app);
}
@PerActivity
@Component(dependencies = ApplicationComponent)
interface MainActivityComponent {
// MainActivity can see any types in SingletonsToExport
// because ApplicationComponent implements it and
// MainActivityComponent depends on ApplicationComponent
void inject(MainActivity activity);
}
class MainActivity extends Activity {
@Inject OkHttpClient client;
@Inject GooglePlayThingamabob playThingamy;
... onCreate etc...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment