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
From the course: Android Dependency Injection with Dagger 2 and Kotlin
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…
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
-
-
-
-
-
(Locked)
When Dagger can't figure it out: @Modules and @Binds5m 6s
-
(Locked)
When it's complicated: @Provides4m 49s
-
(Locked)
When types are not enough: @Named3m 33s
-
(Locked)
Multibinding: Sets4m 42s
-
(Locked)
Multibinding: Maps with simple keys4m 15s
-
(Locked)
Real-world example: Architecture components #14m 29s
-
(Locked)
Real-world example: Architecture components #23m 19s
-
(Locked)
Real-world example: Architecture components #31m 40s
-
(Locked)
Multibinding: Maps with complex keys4m 53s
-
(Locked)
Real-world example: Architecture components solved3m 25s
-
(Locked)
-
-
-