concept time in category dependency injection

This is an excerpt from Manning's book Dependency Injection.
A sauce béarnaise is an emulsified sauce made from egg yolk and butter, that’s flavored with tarragon, chervil, shallots, and vinegar. It contains no water. The biggest challenge to making it is that its preparation can fail. The sauce can curdle or separate, and, if either happens, you can’t resurrect it. It takes about 45 minutes to prepare, so a failed attempt means that you may not have time for a second try. On the other hand, any chef can prepare a sauce béarnaise. It’s part of their training and, as they’ll tell you, it’s not difficult.
Constructor overloads are fairly common in many .NET code bases (including the BCL). Often, the many overloads provide reasonable defaults to one or two full-blown constructors that take all relevant parameters as input. (This practice is called Constructor Chaining.) At times, we see other uses when it comes to DI.
var repository = new SqlOrderRepository(connectionString); var validator = new OrderValidator(repository); #1 var orderService = new OrderService(repository); #1 orderService.AcceptOrder(order); orderService.Dispose(); #2 validator.Validate(order); #3 #1 A single instance of SqlOrderRepository is injected into both OrderValidator and OrderService. These two instances share the same instance of the IOrderRepository Dependency. #2 If OrderService disposes of its injected IOrderRepository at a later point in time, it destroys OrderValidator’s Dependency too. #3 This causes exceptions to be thrown when OrderValidator tries to use it in its Validate method.

This is an excerpt from Manning's book Dependency Injection in .NET.
In my experience, unlearning is vital because people tend to try to retrofit what I tell them about DI and align it with what they think they already know. When this happens, it takes a lot of time before it finally dawns on them that some of their most basic premises are wrong. I want to spare you that experience. So, if you can, try to read this book as though you know nothing about DI.
At times, the value and the operational context are encapsulated in a single ABSTRACTION that works as a combination of both.
To determine when to expire a cached currency, you need to know how much time went by since the currency was cached, so you need access to the current time. DateTime.UtcNow seems like a built-in AMBIENT CONTEXT, but it’s not, because you can’t assign the time—only query it.
Figure 8.13. A consumer requires an IService DEPENDENCY, but if it only uses this DEPENDENCY in a small fraction of the time, it can live for a long time before requiring the services of IService. When it finally invokes IService.SelectItem(), LazyService uses its injected IServiceFactory to create an instance of another IService. It isn’t until this point that the ExpensiveService instance is created. After ExpensiveService is created, all subsequent calls can be delegated to it.
![]()

This is an excerpt from Manning's book Dependency Injection: Design Patterns Using Spring and Guice.
Cool! At the time of creating the Emailer, it’s up to you to provide its dependencies. This allows you to choose particular flavors of its services that suit your needs (French, Japanese, and so on) as shown in figure 1.5.
Since you end up connecting the pipes yourself at the time of construction, this technique is referred to as construction by hand. In the previous example we used a setter method (a method that accepts a value and sets it as a dependency). You can also pass in the dependency via a constructor, as per the following example:
An important practice regards the state of fields once set. In most cases we want fields to be set once (at the time the object is created) and never modified again. This means not only that the dependent can rely on its dependencies throughout its life but also that they are ready for use right away. Such fields are said to be immutable. If you think of private member variables as a spatial form of encapsulation, then immutability is a form of temporal encapsulation, that is, unchanging with respect to time. With respect to dependency injection, this can be thought of as freezing a completely formed object graph.
/**
* Configure the constraint validator based on the elements
* specified at the time it was defined.
*
* @param constraint the constraint definition
*/
public void initialize(Length constraint) {
min = constraint.min();
max = constraint.max();
}