Written by Mark Pringle | Last Updated on Monday, November 28, 2022

ASP.NET Core General Information

As discussed in the article What is Dependency Injection? ASP.NET Core Basics, Dependency injection is a software design model that allows one object or class in an application to use another object or class in the application.

In ASP.NET Core, there are three types of dependency injection: Construction Injection, Setter Injection, and Interface based Injection. Let’s examine all three.

Constructor Injection

Constructor injection is the most common type of dependency injection. In the constructor injection, you create an instance of your dependency. The injector passes the dependencies or services as parameters to the client class constructor.

Setter Injection (aka Property Injection)

In the Setter injection, the injector passes the dependencies as properties to the client class.

Method Injection

In this type of injection, you create an instance of your dependency. The injector passes the instance of the dependency as a method(s) to the client class.