any recommended ways about eagerly creating a dagg...
# dagger
w
any recommended ways about eagerly creating a dagger provided object? i probably don't want dagger to create it, but in my application i have an
@Inject
field that is never used just so my object gets created - this seems odd though
g
may wrap it in Lazy like @Inject Lazy<Foo> foo; https://google.github.io/dagger/api/2.10/dagger/Lazy.html
p
Just delete your field if it's not used
w
@gergo what would i gain from having it lazy? i want it to start when my application starts (android) since its sort of a background task.
@Paul Woitaschek the field isn't used but the injection is utilized to create the object (and thus start the background service / task thing)
p
So you want an object not to be created but created? I don't get it
Anyways, dagger creates things. You could use a providing method on your component
g
ohh i missundestood your intentions then. well if you don't want to inject it, then you may provide it from the component, and create it like component.provideFoo() in your application's onCreate method which will create the object but you won't have the field. you want something like this right?
w
@Paul Woitaschek i want it to be created but there is no use for me to have a reference to that object. i.e. the object sets up a listener in its init method
p
Then don't do it in the init block
Have a init() method and use a provisioning method on your component and call init() on it, that's more explicit than having a class that magically starts doing things by instantiating it