Dagger 2 Deep Dive (18/55) - Injecting a Jetpack ViewModel

Опубликовано: 26 Июль 2026
на канале: Brandon Gogetap
595
6

The HomeViewModel has an inject annotated constructor. Because of the way Jetpack ViewModels interact with Fragments, we can't directly inject HomeViewModel into the HomeFragment.

The solution to this is to use a ViewModel.Factory.

In this video, we'll create a simple reusable ViewModel.Factory that our Fragments will be able to inject. This factory will provide the injectable ViewModels to the Fragments via the lifecycle framework built into Fragments.

Project: https://github.com/bgogetap/GitHubBro...

This video is part of a series. See the full playlist here:    • Dagger 2 Deep Dive