M
M
mitaichik2016-11-09 00:56:34
Android
mitaichik, 2016-11-09 00:56:34

Dagger 2: Can lazy creation be configured by default?

Hello!
In general, I started to study/implement Dagger 2 and got screwed: I made all dependencies normal (I understand that they are created by the whole module at once), but I need them all to be created on demand. Is it possible to configure Dagger to work like this by default? And then you will have to redo a hundred places ...
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mitaichik, 2016-12-03
@mitaichik

In general, I misunderstood everything:
Dagger creates dependencies on demand (which is what I wanted). Lazy envy is needed even when a dependency needs to be injected without creating it.

A
Alexey Ershov, 2016-11-17
@alaershov

This is impossible from the point of view of the language itself. If you have a field of an ordinary object type, it is either null if the injection has not yet worked, or not null if the injection has already worked. It is impossible in principle to make the field not null, and lazily initialized the first time it is accessed.
So the answer to your question is "no". And Dagger has nothing to do with it :)
Another question arises: do you really need them all to be created on demand? Are you experiencing a noticeable performance hit when initializing an object graph? What is the real problem with non-lazy initialization?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question