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

When types are not enough: @Named

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

Start my 1-month free trial

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…

Contents