Posts

Showing posts with the label dagger

Dagger Lazy during constructor injection

Dagger Lazy during constructor injection I realize that the recommended way of accomplishing Lazy injection with Dagger is to add Lazy to a field injection point. For instance, Lazy Lazy class Foo { @Inject lateinit var bar: Lazy<Bar> fun useBar() = bar.get().doSomething() } What about using constructor injection? I have not seen anyone doing it. class Foo @Inject constructor(private val fizz: Fizz, private val bar: Lazy<Bar>) { fun useBar() = bar.get().doSomething() } To summarize when doing Dagger lazy injection, can I use Lazy<Bar> in a constructor? Or is my only option to move Lazy<Bar> to a field injection while keeping other non-Lazy dependencies in the same class injected via the constructor? Lazy<Bar> Lazy<Bar> Thanks for any pointers! Have you tried? – AutonomousApps Jul 2 at 7:30 ...