Injecting Services to ASP.NET Core Controller Actions

ASP.NET Core comes with a thin but rich and powerful built-in dependency injection mechanism we can use to inject instances to controllers and some other parts of web applications. Although constructor injection is the most famous dependency injection method for controllers, there is also dependency injection to controller actions available. This post introduces controller action injection and shows how to benefit from it.
Constructor Injection With Controllers
Controller action injection is a great feature to use with controllers where most of the actions need some specific service that others don’t need. In ASP.NET Core, it’s traditional to use constructor injection. Let’s take a look at the following controller.

Link: https://dzone.com/articles/injecting-services-to-aspnet-core-controller-actio?utm_medium=feed&utm_source=feedpress.me&utm_campaign=Feed%3A+dzone%2Fwebdev