Chapter 3. Investigating DI
This chapter covers:
- Learning about injection by setter and constructor
- Investigating pros and cons of injection idioms
- Identifying pitfalls in object graph construction
- Learning about reinjecting objects
- Discovering viral injection and cascaded object graphs
- Learning techniques to inject sealed code
“The best way to predict the future is to invent it.”
Alan Kay
Previously we discussed two methods of connecting objects with their dependencies. In the main we have written classes that accept their dependencies via constructor. We have also occasionally used a single-argument method called a setter method to pass in a dependency. As a recap, here are two such examples from chapter 1:
These are two common forms of wiring. Many dependency injectors also support other varieties and bias toward or away from these idioms.