Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The patterns presented in this chapter are a central part of DI. Armed with a COMPOSITION ROOT and an appropriate mix of the DI patterns, you can implement POOR MAN’S DI. When applying DI, there are many nuances and fine details to learn, but the patterns cover the core mechanics that answer the question, how do I inject my Dependencies?
These patterns aren’t interchangeable. In most cases, your default choice should be CONSTRUCTOR INJECTION, but there are situations where one of the other patterns affords a better alternative. Figure 4.12 shows a decision process that can help you decide on a proper pattern, but if in doubt, choose CONSTRUCTOR INJECTION—you can never go horribly wrong with that choice.