I’m new to Dagger 2. I have this scenario, I wan't to inject an object across my app (in presenters, in api)
I do not have a way to provide it initially. It is not created till after authentication at some stage in my app.
From the documentation http://google.github.io/dagger/
I see Lazy loading might be a way to solve this e.g
@Inject
Lazy<Grinder> lazyGrinder;
and then get the value like this using: lazyGrinder.get().grind();
My questions are:
- Can I safely swap the object after this with a new one?
- Are there any other recommended ways to do this?
Thanks
Lazy<T>
only once. It gave me deadlocks on start-up. Never again. I have no idea what I did wrong, by the way. I personally would just create a singletonHolder
object, as inGrinderHolder
and set it in when you have it (null
otherwise) – Oldster