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.
Multibinding: Maps with complex keys
From the course: Android Dependency Injection with Dagger 2 and Kotlin
Multibinding: Maps with complex keys
- [Instructor] In the last video we worked a fairly complex example using Dagger in a real world application. It didn't quite work, but I promised that we could make it work. In the next couple of videos I'm going to make good on that promise. The Reisner code didn't work, as the Dagger is just very picky about matching types. We told it how to create a class of star, instead of a class of out ViewModel, which is what we need. So, what we need now, is a way to tell Dagger about more complex key types. Introducing the @MapKey annotation. The first thing to notice about this annotation is that it's a little weird. It's an annotation that annotates annotations. It is an annotation that creates annotations. The MapKey annotation does two things. It creates a new annotation that we can use to create keys for Dagger-generated maps. It also describes the key object, whose code Dagger will auto-generate. The arguments to the annotation class are exactly the fields of the key class. Because…
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)
-
-
-