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 solved

Real-world example: Architecture components solved

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

Start my 1-month free trial

Real-world example: Architecture components solved

- [Instructor] In previous videos we worked a complex example using Dagger in a real world application, and it didn't quite work, but I promise that we could fix it. The reason it didn't work is that we couldn't yet tell Dagger to create a key of type class out ViewModel. We now know how to create more complex key types using the @MapKey annotation. In the last video, we used @MapKey to create a new key annotation, that created a mapkey from an enum. In this video, we'll see how to create a map with a more complex key. Again note, that the complete documentation for the syntax for annotation classes is available at kotlinlang.org. I'm not going to write all this code out, it's very similar to code we've seen before. What I do want to point out, is that the @MapKey annotation, when applied to an annotation class with multiple parameters, must have it's unwrap value parameter set false. The MapKey annotation parameter unwrap value has to be set false. This creates a new annotation…

Contents