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

When Dagger can't figure it out: @Modules and @Binds

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

Start my 1-month free trial

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…

Contents