Last active
August 29, 2017 20:10
-
-
Save fkruege/230db5273de0f9205ed02f0622242748 to your computer and use it in GitHub Desktop.
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
| @Scope | |
| @Retention(AnnotationRetention.RUNTIME) | |
| annotation class ActivityScope |
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
| @Singleton | |
| @Component | |
| interface AppComponent { | |
| } |
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
| @Singleton | |
| @Component | |
| interface AppComponent { | |
| @Component.Builder | |
| interface Builder { | |
| @BindsInstance | |
| fun application(myApp: MyApp): Builder | |
| fun build(): AppComponent | |
| } | |
| } |
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
| @Singleton | |
| @Component(modules = arrayOf(AndroidInjectionModule::class)) | |
| interface AppComponent { | |
| @Component.Builder | |
| interface Builder { | |
| @BindsInstance | |
| fun application(myApp: MyApp): Builder | |
| fun build(): AppComponent | |
| } | |
| fun inject(myApp: MyApp) | |
| } |
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
| @Singleton | |
| @Component(modules = arrayOf( | |
| AndroidInjectionModule::class | |
| , NetworkingModule::class | |
| , AndroidModule::class | |
| )) | |
| interface AppComponent { | |
| @Component.Builder | |
| interface Builder { | |
| @BindsInstance | |
| fun application(myApp: MyApp): Builder | |
| fun build(): AppComponent | |
| } | |
| fun inject(myApp: MyApp) | |
| } |
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
| @Singleton | |
| @Component(modules = arrayOf( | |
| AndroidInjectionModule::class | |
| , NetworkingModule::class | |
| , AndroidModule::class | |
| , MainActivityModule::class | |
| , NotificationsActivityModule::class | |
| )) | |
| interface AppComponent { | |
| @Component.Builder | |
| interface Builder { | |
| @BindsInstance | |
| fun application(myApp: MyApp): Builder | |
| fun build(): AppComponent | |
| } | |
| fun inject(myApp: MyApp) | |
| } |
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
| open class MyApp : Application(), HasActivityInjector { | |
| @Inject protected lateinit var dispatchingActivityInjector: DispatchingAndroidInjector<Activity> | |
| override fun onCreate() { | |
| super.onCreate() | |
| injectDagger() | |
| } | |
| open fun injectDagger() { | |
| DaggerAppComponent | |
| .builder() | |
| .application(this) | |
| .build() | |
| .inject(this) | |
| } | |
| override fun activityInjector(): AndroidInjector<Activity> { | |
| return dispatchingActivityInjector | |
| } | |
| } |
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
| @Module | |
| abstract class MainActivityModule { | |
| @ActivityScope | |
| @ContributesAndroidInjector | |
| abstract fun contibutesMainActivity(): MainActivity | |
| @ActivityScope | |
| @Binds | |
| abstract fun bindsMainActivityToMainView(mainActivity: MainActivity): MainView | |
| } |
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
| @Module | |
| class MainActivityDependenciesModule { | |
| @Provides | |
| @ActivityScope | |
| fun provideMainActivityDependency(mainView: MainView | |
| , myPreferences: MyPreferences | |
| , commonClass: CommonClass | |
| , myNetworkingService: MyNetworkingService): MainActivityDependency { | |
| return MainActivityDependency(mainView, myPreferences, commonClass, myNetworkingService) | |
| } | |
| @Provides | |
| @ActivityScope | |
| fun provideNavigator(activity: MainActivity): Navigator { | |
| return Navigator(activity) | |
| } | |
| @Provides | |
| @ActivityScope | |
| fun provideCommonClass(): CommonClass { | |
| return CommonClass() | |
| } | |
| } |
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
| @Provides | |
| @ActivityScope | |
| fun provideMainView(activity: MainActivity): MainView { | |
| return activity | |
| } |
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
| @Module | |
| abstract class MainActivityModule { | |
| @ActivityScope | |
| @ContributesAndroidInjector | |
| (modules = | |
| arrayOf(MainActivityDependenciesModule::class | |
| , HomeFragmentModule::class | |
| , DashboardFragmentModule::class | |
| )) | |
| abstract fun contibutesMainActivity(): MainActivity | |
| @ActivityScope | |
| @Binds | |
| abstract fun bindsMainActivityToMainView(mainActivity: MainActivity): MainView | |
| } |
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
| @Module | |
| abstract class HomeFragmentModule { | |
| @FragmentScope | |
| @ContributesAndroidInjector(modules = arrayOf(HomeFragmentDependenciesModule::class)) | |
| abstract fun contibutesHomeFragment(): HomeFragment | |
| @FragmentScope | |
| @Binds | |
| abstract fun bindHomeFragmentToHomeView(homeFragment: HomeFragment): HomeView | |
| } |
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
| @Module | |
| abstract class DashboardFragmentModule { | |
| @FragmentScope | |
| @ContributesAndroidInjector(modules = arrayOf(DashboardFragmentDependenciesModule::class)) | |
| abstract fun contibutesDashboardFragment(): DashboardFragment | |
| } |
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
| class MainActivity : | |
| AppCompatActivity() | |
| , HasSupportFragmentInjector | |
| , MainView { | |
| @Inject | |
| lateinit var mainActivityDependency: MainActivityDependency | |
| @Inject | |
| lateinit var navigator: Navigator | |
| @Inject | |
| lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment> | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| AndroidInjection.inject(this) | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) | |
| } |
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
| kapt { | |
| generateStubs = true | |
| } |
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
| implementation "com.google.dagger:dagger:$dagger" | |
| kapt "com.google.dagger:dagger-compiler:$dagger" | |
| implementation "com.google.dagger:dagger-android:$dagger" | |
| implementation "com.google.dagger:dagger-android-support:$dagger" | |
| kapt "com.google.dagger:dagger-android-processor:$dagger" |
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
| @Singleton | |
| @Component(modules = arrayOf( | |
| AndroidInjectionModule::class | |
| , NetworkingModule::class | |
| , AndroidModule::class | |
| , MainActivityModule::class | |
| , NotificationsActivityModule::class | |
| )) | |
| interface AppComponent { | |
| @Component.Builder | |
| interface Builder { | |
| @BindsInstance | |
| fun application(myApp: MyApp): Builder | |
| fun build(): AppComponent | |
| } | |
| fun inject(myApp: MyApp) | |
| } | |
| @Module | |
| class NetworkingModule { | |
| @Provides | |
| @Singleton | |
| fun provideNetworkingService(myApp: MyApp): MyNetworkingService { | |
| return MyNetworkingServiceImpl(myApp) | |
| } | |
| } |
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
| @Module | |
| class NetworkingModule { | |
| @Provides | |
| //@Singleton | |
| fun provideNetworkingService(myApp: MyApp): MyNetworkingService { | |
| return MyNetworkingServiceImpl(myApp) | |
| } | |
| } |
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
| @Module | |
| class NetworkingModule { | |
| @Provides | |
| @Singleton | |
| fun provideNetworkingService(myApp: MyApp): MyNetworkingService { | |
| return MyNetworkingServiceImpl(myApp) | |
| } | |
| } | |
| @Module | |
| class AndroidModule { | |
| @Provides | |
| @Singleton | |
| fun providePreferences(myApp: MyApp): MyPreferences { | |
| return MyPreferences(myApp) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment