Skip to content

Commit

Permalink
Merge pull request #5 from stanwood/readme-providing-viewmodels-inter…
Browse files Browse the repository at this point in the history
…actors-repositories

Clarify how to provide ViewModels, Repositories and Interactors
  • Loading branch information
ubuntudroid authored Dec 5, 2018
2 parents 5af1cee + 7fe03f2 commit 4d91ca9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions di/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
```
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4d91ca9

Please sign in to comment.