Chapter 5: Dependency Injection in .NET
A big issue that an enterprise application can face is the complexity of wiring different elements together and managing their lifetimes. To address this, we use the Inversion of Control (IoC) principle, which recommends removing the dependency between objects. By delegating the flow of control, IoC makes the program extensible and increases the modularity. Events, callback delegates, the observer pattern, and Dependency Injection (DI) are some of the ways to achieve IoC.
In this chapter, we will learn about the following:
- What is DI?
- DI in ASP.NET Core 5
- Managing application services
- Using third-party containers
By the end of this chapter, you'll have a good idea of DI, leveraging DI in .NET 5 applications, the types of scopes provided in ASP.NET Core 5, and how to leverage them in your projects.