Understanding the basics of DI
Before starting down the path of using DI in our project, we should take some time to understand what DI is and why it is fundamental for building modern applications. You will often see DI referenced with another related concept, Inversion of Control (IoC). Let’s discuss these two concepts by doing the following:
- Clarify the relationship between them
- Prepare you to use DI properly in this chapter
DI is used by modern developers to inject dependent objects into a class rather than creating instances of the objects inside the class. There are several ways to inject those objects:
- Method injection: Objects are passed as parameters to a method in the class
- Property injection: Objects are set through properties
- Constructor injection: Objects are passed as constructor parameters
The most common method of DI is constructor injection. In this chapter, we will be using both property injection and constructor injection...