Skip to content

Instantly share code, notes, and snippets.

@rohankandwal
Created May 10, 2018 11:02
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 rohankandwal/a67e92811c5fa605eaedfdf211dff4ac to your computer and use it in GitHub Desktop.
Save rohankandwal/a67e92811c5fa605eaedfdf211dff4ac to your computer and use it in GitHub Desktop.
AppModule - Used to inject fragments, service, activities with other modules
@Module(includes = {
AndroidInjectionModule.class, RepositoryModule.class,
MySharedPreferencesModule.class
ViewModelModule.class, LocalRepositoryModule.class, MQTTModule.class
})
abstract class AppModule {
/*
* Singleton annotation isn't necessary since Application instance is unique but is here for
* convention. In general, providing Activity, Fragment, BroadcastReceiver, etc does not require
* them to be scoped since they are the components being injected and their instance is unique.
*
* However, having a scope annotation makes the module easier to read. We wouldn't have to look
* at what is being provided in order to understand its scope.*/
abstract Application application(SmartHomeApplication app);
// Injecting Activities
@PerActivity
@ContributesAndroidInjector(modules = { ActivityModule.class })
abstract SplashScreenActivity splashScreenActivityInjector();
@PerActivity
@ContributesAndroidInjector(modules = { ActivityModule.class })
abstract HomeScreenActivity mainActivityInjector();
@PerActivity
@ContributesAndroidInjector(modules = {ActivityModule.class})
abstract LoginActivity loginActivityInjector();
@PerActivity
@ContributesAndroidInjector(modules = {ActivityModule.class})
abstract RegistrationActivity registrationActivityInjector();
// Injecting Services
@PerService
@ContributesAndroidInjector
abstract VoiceProcessingService voiceProcessingServiceInjector();
// Injecting Fragments
@ContributesAndroidInjector
abstract MyFavoritesFragment myFavoritesFragmentInjector();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment