Last active
August 29, 2015 14:09
-
-
Save cgruber/5b3a4f10d88d04154e89 to your computer and use it in GitHub Desktop.
Component exporting to dependent components
This file contains hidden or 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
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