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 complex keys

Multibinding: Maps with complex keys

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

Start my 1-month free trial

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…

Contents