concept Captive Dependencies in category dependency injection

appears as: Captive Dependencies
Dependency Injection

This is an excerpt from Manning's book Dependency Injection.

Don’t store injected method Dependencies. This leads to Temporal Coupling, Captive Dependencies, or hidden side effects.10  A method should use the Dependency or pass it on, and should refrain from storing such a Dependency. The use of Method Injection is quite common in the .NET BCL, so we’ll look at an example next.

10  We’ll discuss Captive Dependencies in section 8.4.1.

Captive Dependencies are a common problem when you’re working with a DI Container. This is caused by the dynamic nature of DI Containers that make it easy to lose track of the shape of the object graphs you’re building. As the previous example showed, however, the problem can also arise when working with Pure DI. By carefully structuring code in the Pure DI Composition Root, you can reduce the chance of running into this problem. The following listing shows an example of this approach.