From 7fe03f275ffcf014444439a06cceb3e75a87e16e Mon Sep 17 00:00:00 2001 From: Sven Bendel Date: Mon, 3 Dec 2018 17:31:31 +0100 Subject: [PATCH] Clarify how to provide ViewModels, Repositories and Interactors --- di/README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/di/README.md b/di/README.md index 358c956..f563972 100644 --- a/di/README.md +++ b/di/README.md @@ -99,12 +99,7 @@ The actual provides are declared in the sub-module: @Module class HomeFragmentSubModule { - @Provides - @FragmentScope - internal fun provideViewModel( - homeInteractor: HomeInteractor, - settingsInteractor: SettingsInteractor - ) = HomeViewModel(homeInteractor, settingsInteractor) + // provide @FragmentScope annotated dependencies here } ``` @@ -137,9 +132,16 @@ class HomeFragment : Fragment(), HasSupportFragmentInjector { There is not much to do for ViewModels except for adding a constructor annotated with `@Inject`: ```kotlin +@FragmentScope class HomeViewModel @Inject constructor(/* inject properties here if you want */) : ViewModel() {} ``` +## For each Interactor/Repository + +Interactors and repositories are usually also provided right the same like ViewModels and scoped as `Singleton` or `FragmentScope`/`ActivityScope`. + +Using modules is rarely needed to provide them. + ## What else do I need? Due to the nature of how libraries and dagger work we cannot provide all necessary classes to get DI up and running.