DI in ASP.NET Core 5
In this section, we will take a detailed look at the DI supported in ASP.NET Core 5.
.NET 5 comes with IoC Container built in which simplifies DI. This comes with the Microsoft.Extensions.DependencyInjection
NuGet package. The ASP.NET Core 5 framework itself relies heavily on this. To support DI, a container needs to support three basic actions on objects/services:
- Registering: The container should have the provisions to register the dependencies. This will help to map the correct type to a class so that it can create the right dependency instance.
- Resolving: The container should resolve the dependency by creating the dependency object and injecting it into the dependent instance. IoC Container manages the creation of registered objects by passing in all the required dependencies.
- Disposing: The container is responsible for managing the lifetime of the dependencies created through it.
In .NET 5, the term service refers to the dependency...