With traditional dependency injection (DI) methods, the parent or calling object supplies the dependencies to the child class. However, there are many cases where the dependencies have a single implementation. In these cases, a pragmatic approach would be to ask yourself, why inject the dependency at all? In this chapter, we will examine just-in-time (JIT) dependency injection, a strategy that gives us many of the benefits of DI, like decoupling and testability, without adding parameters to our constructors or methods.
The following topics will be covered in this chapter:
- JIT injection
- Advantages of JIT injection
- Applying JIT injection
- Disadvantages of JIT injection