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.

When it's complicated: @Provides

When it's complicated: @Provides

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

Start my 1-month free trial

When it's complicated: @Provides

- [Instructor] In the previous video, I introduced modules as a way of giving Dagger hints about things it can't figure out for itself. Up until this point, we've used an @Inject annotation on a constructor to tell Dagger how to create every object we've needed. What happens though when there's no way to do that? Suppose, for instance, the object isn't even part of your code, but instead is part of some third party library that you're using? Or maybe your code created an object a while ago and you simply need to use it now? In either case, if Dagger can't figure out how to create an object from an @Inject annotated constructor, it won't be able to create any of the things that depend on it. We can fix that using a module. For example, let's suppose that the persistence store mechanism used by a presenter is part of a third-party Java library. Maybe the library looks something like this. There's a static get method that returns the implementation of the DAO and there's a store method…

Contents