DEV Community

Discussion on: Dagger-Dot-Android Part 2: ViewModels and ViewModel Factories

Collapse
 
rafipanoyan profile image
Rafi Panoyan

Hi Tony !

Do we really need ViewModels if our Dagger components are scoped correctly ?

In the article you mention that we care about ViewModels because :

  • they live oustide Activity/Fragments -> this is also true for your scoped subcomponents inside the Dagger graph. Rotations could be handled with only Dagger

  • they live inside Activity/Fragments, notifying the LiveData observer only on the started state -> this is handled by LiveData and the LifecycleOwner (Activity/Fragment), but ViewModel are not necessary for this to work

IMO if the Dagger graph is well scoped, we could get all the benefits that you are describing in this (valuable) article, without bothering with ViewModel.