From the course: Android Dependency Injection with Dagger 2 and Kotlin
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Multibinding: Maps with simple keys
From the course: Android Dependency Injection with Dagger 2 and Kotlin
Multibinding: Maps with simple keys
- As we learned in the last video, Dagger can build collections of objects for us. This capability is called multibinding. We've learned how to create sets of objects. Let's continue and explore multibinding by looking at how we can create simple maps. Dagger can create simple maps with two key types. The two key types are strings and classes. Let's start with a map whose keys are strings. Suppose we want to extend the application from the last video so that the decorators are in a map whose key is the name of the decorator. Our new processor, in addition to being able to apply all of the decorations at once, can apply a single decoration selected by it's name. Again, Dagger could create this processor if it could just figure out how to create the map on which it depends. The basic structure for the new code is going to be very similar to the structure we used for the multibinding example. As you might've guessed, building a map is pretty simple. It requires only two new annotations…
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
-
-
-
-
-
When Dagger can't figure it out: @Modules and @Binds5m 6s
-
When it's complicated: @Provides4m 49s
-
When types are not enough: @Named3m 33s
-
Multibinding: Sets4m 42s
-
Multibinding: Maps with simple keys4m 15s
-
Real-world example: Architecture components #14m 29s
-
Real-world example: Architecture components #23m 19s
-
Real-world example: Architecture components #31m 40s
-
Multibinding: Maps with complex keys4m 53s
-
Real-world example: Architecture components solved3m 25s
-
-
-
-