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.

Lazy and provider injection

Lazy and provider injection

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

Start my 1-month free trial

Lazy and provider injection

- [Narrator] As I've said before, once you're comfortable using Dagger's at time inject and at time component annotations, all the rest is just icing. Who doesn't like icing, though? Let's have a look at a couple more of Dagger's cool tricks. First of all, Provider injection. Then, Lazy injection. Suppose that our application needs to create a new connection to to the server for each new client request. That is, a single instance of client objects needs to create a new instance of a connection object for each call to fetch data. Of course, there's nothing in the actual demonstration code here that requires anything like that. I'm not including anything more than a skeleton of a real application. In a real application, though, a single client needing multiple connections would be an entirely likely scenario. Think about this, instead of injecting a dependency into the object, we want to inject a way of creating the dependency. Well, way of creating a dependency is the definition of…

Contents