square / dagger

A fast dependency injector for Android and Java.
https://square.github.io/dagger/
Apache License 2.0
7.31k stars 3.06k forks source link

Website documentation about using dagger #536

Closed ahmed-hamdy90 closed 8 years ago

ahmed-hamdy90 commented 8 years ago

Injecting Provider has the possibility of creating confusing code, and may be a design smell of mis-scoped or mis-structured objects in your graph. Often you will want to use a Factory or a Lazy or re-organize the lifetimes and structure of your code to be able to just inject a T. Injecting Provider can, however, be a life saver in some cases. A common use is when you must use a legacy architecture that doesn't line up with your object's natural lifetimes (e.g. servlets are singletons by design, but only are valid in the context of request-specfic data).

I think Factory<T> must be Provider<T>

JakeWharton commented 8 years ago

This is saying that manually-written factory or lazy are alternatives to investigate to ultimately allow you to inject a T.