From the course: Android Dependency Injection with Dagger 2 and Kotlin
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
When types are not enough: @Named
From the course: Android Dependency Injection with Dagger 2 and Kotlin
When types are not enough: @Named
- [Instructor] Do you remember back when we first started using Dagger to build our dependence tree? Well, I made a shortcut back there. Now, I don't know if you notice it, but it's been nagging me. Remember when I took this code our hand built factories for the network connection and converted it to a Dagger version? Well I cheated. I converted it to this code. I swooshed two factories together into one. I did it because, as I've said several times now, Dagger matches types exactly. We could provide at most one string type in our entire dependency tree. If I use Dagger to provide an object of type string, then every object that depended on that type string would get the exact same string. Well that's a shame. We're frequently going to want to use strings to configure things and Dagger does have a way to do it. Here's the code pretty much as we left it. We're going to add a module and use it to inject the endpoint. So as you can see, I've added a module, the connection module, to our…
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
-
-
-
-