In all Android projects I posted on Google Play I've always used for dependency injection Roboguice. Recently I was able to see the benefits of Roboguice 3.0 and then I decided to investigate other libraries on Android for dependency injection not pigeonhole with Roboguice only. And how i found Dagger, and found an attractive concept, LAZY INJECTION, also I read the articule Dagger vs. Guice.
- Does Roboguice this functionality or something like this?
- If not, the limitation is given because Roboguice use reflection and Dagger works by generating code up front?
Lazyis just a box that defers resolving the binding. It's extremely similar toProviderexcept with one important distinction: it will cache the value from the first call and return it on subsequent calls.For bindings to singletons, there is no behavior difference from the consumer perspective. Both a
Lazy<Foo>and aProvider<Foo>will both lazily look up the binding and return the same instance each time.The only behavior change is when you have a non-singleton binding.
You can implement
Lazyyourself with Guice like this: