What is DI?
DI is a technique in which an object receives objects that it depends on. The DI pattern fulfills the DI principle covered as part of the single-responsibility principle, open-closed principle, Liskov substitution principle, interface segregation principle, and dependency inversion principle (SOLID) design principles in Chapter 1, Designing and Architecting the Enterprise Application. With the use of DI, code will be more maintainable, readable, testable, and extensible.
DI is one of the most well-known methods to help achieve better maintainable code. DI has three entities involved, as shown in the following diagram:
Figure 5.1 – DI relationship
The Injector creates an instance of Service and injects it into the Client object. The Client depends on the injected Service to perform its operations—for example, in the enterprise application that we are going to build, IOrderRepository is responsible for create, read, update, and delete...