From the course: Android Dependency Injection with Dagger 2 and Kotlin
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Real-world example: Architecture components #2
From the course: Android Dependency Injection with Dagger 2 and Kotlin
Real-world example: Architecture components #2
- [Instructor] In a real world example, we've enabled field injections so that Dagger can give our activity a View Model factory. What we haven't done is told Dagger how to create that View Model factory. So let's do that. What we have to do here is teach Dagger to create the field that's being injected into the activity, the View Model factory. Well that part's easy. Let's just annotate the constructor with an @ sign inject annotation. The only thing that's left to do is to explain to Dagger how to create the map on which the View Model factory depends. This is the most complicated part. We need to create a map whose keys are classes and whose values are providers of View Models. That's View Model factories. First of all, remember, the Dagger matches types exactly. Our implementation of View Model, View Model one, is not exactly the type of View Model. The View Model is defined over in the activity file, let's look at it. Our View Model is type View Model one and it extends View…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
When Dagger can't figure it out: @Modules and @Binds5m 6s
-
(Locked)
When it's complicated: @Provides4m 49s
-
(Locked)
When types are not enough: @Named3m 33s
-
(Locked)
Multibinding: Sets4m 42s
-
(Locked)
Multibinding: Maps with simple keys4m 15s
-
(Locked)
Real-world example: Architecture components #14m 29s
-
(Locked)
Real-world example: Architecture components #23m 19s
-
(Locked)
Real-world example: Architecture components #31m 40s
-
(Locked)
Multibinding: Maps with complex keys4m 53s
-
(Locked)
Real-world example: Architecture components solved3m 25s
-
(Locked)
-
-
-