https://kotlinlang.org logo
#dagger
Title
# dagger
r

ritesh

10/05/2019, 7:18 PM
@JvmStatic @Provides @Singletonn fun providesHandler( ): SomeHandler = HandlerObject.init() This is the provider, i have inside the some module and that module is sits in the application component and it's singleton. I know that dagger generates all the module providers classes at compile time, as gets the instance dependency through the
get()
overriden method in the class. As all classes required for the DI graph are created at compile time. I was wondering when the actual creation of the object happens, when
get()
is actually called. Does it gets called and object is created when it's requested through
@inject
or happens at compile time and just returns when
@inject
gets called.
w

wasyl

10/05/2019, 7:27 PM
If you inspect Dagger’s source code, you’ll find a lot of
Provider
classes. These are invoked when the instance is supposed to be injected somewhere, and only then objects get created. So your
HandleObject.init()
will be called only when it’s injected, not before. Anyway or happens at compile time doesn’t make much sense, as objects aren’t really created during compilation
r

ritesh

10/05/2019, 7:32 PM
Thanks for answering @wasyl My thought was same as it should be created only when the dependencies are requested though,
field
or
constructor
or any other injection types. I am stuck with a bug and just wanted to make sure. Thanks again!