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

Multibinding: Maps with simple keys

From the course: Android Dependency Injection with Dagger 2 and Kotlin

Start my 1-month free trial

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…

Contents