concept lifetime in category dependency injection

This is an excerpt from Manning's book Dependency Injection.
Object Composition isn’t the only dimension of control that we remove: a class also loses the ability to control the lifetime of the object. When a Dependency instance is injected into a class, the consumer doesn’t know when it was created, or when it’ll go out of scope. This should be of no concern to the consumer. Making the consumer oblivious to the lifetime of its Dependencies simplifies the consumer.
Figure 6.6 The consuming class
HomeControllercontrols the lifetime of itsIProductRepositoryDependency. It does so by requesting a Repository instance from theIProductRepositoryFactoryDependency and callingDisposeon theIProductRepositoryinstance when it’s done with it.![]()
Listing 8.10 Managing a Singleton Lifestyle
public class CommerceControllerActivator : IControllerActivator { private readonly IUserContext userContext; #1 private readonly IProductRepository repository; #1 public CommerceControllerActivator() { this.userContext = new FakeUserContext(); #2 this.repository = new InMemoryProductRepository(); #2 } ... private HomeController CreateHomeController() { return new HomeController( #3 new ProductService( #3 this.repository, #3 this.userContext)); #3 } } #1 Storage locations for Singleton instances keep the Singleton Dependencies referenced for the lifetime of the Composer. #2 Creates Singletons in the Composer’s constructor #3 Every time the Composer is asked to resolve a HomeController instance, it creates a Transient ProductService with the two Singletons injected into it.
Don’t bind the lifetime of a Dependency to the lifetime of a thread. The lifetime of a thread is often unclear, and using it in an asynchronous framework can cause multi-threading issues. Instead, use a proper Scoped Lifestyle or hide access to the thread-static value behind a Proxy.

This is an excerpt from Manning's book Dependency Injection in .NET.
However, OBJECT COMPOSITION isn’t the only dimension of control that we remove, because a class also loses the ability to control the lifetime of the object. When a DEPENDENCY instance is injected into a class, the consumer doesn’t know when it was created, or when it will go out of scope. Many times, this is of no concern to the consumer, but in other cases, it may be.
Just as the sommelier intimately knows the contents of the restaurant’s wine cellar and can make a far more informed decision than we can, so should we trust the COMPOSER to be able to control the lifetime of DEPENDENCIES more efficiently than the consumer. Composing and managing components is its single responsibility.
This section discusses the principles behind managing lifetimes with a DI CONTAINER, so I won’t go into great detail about particular containers. As is the case throughout part 3 of this book, I use POOR MAN’S DI to illustrate the concepts.