What is DI?
DI is a technique in which an object receives the objects that it depends on. The DI pattern fulfills the DI principle covered as part of the 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 Figure 5.1:
Injector creates an instance of Service and injects it into the Client object. 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 the CRUD operations on the Order
entity. IOrderRepository
will be instantiated by runtime and injected into OrderController
.
IoC Container, also known as DI Container, is a framework for implementing...