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.
When Dagger can't figure it out: @Modules and @Binds
From the course: Android Dependency Injection with Dagger 2 and Kotlin
When Dagger can't figure it out: @Modules and @Binds
- [Instructor] Sometimes Dagger need help figuring out how to build a dependency graph. Let's mean modules, that tool Dagger use so that we can give it that help. Here's an example of a place that Dagger needs help. Remember, Dagger creates it's dependency tree by matching types. In our demonstration code a client depends on a connection. Because Dagger knows how to create a connection it knows how to create a client. But what if, as is probably good practice, the client depended on an interface instead of a concrete class. What if connection were an interface and Dagger could not create it. Because it can't create a connection it can't create the client. Here's our network connection. The network connection is an implementation of the connection interface. Here's the connection interface. And you can see that our client depends on a connection, the interface, not a network connection. If we try and build this the build will fail. It fails with a missing binding error. It says…
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
-
-
-
-