ASP.NET Core | Dependency injection for controllers
Dependency Injection is a design pattern used to inject the object dependencies inside controllers. ASP.NET core supports built-in dependency injection, just you need to register those services in the startup file inside
You can perform dependency injection in two ways.
ConfigureServices
method. You can add services as constructor parameters, ASP.NET Core runtime will resolve these dependencies from the service container.You can perform dependency injection in two ways.
- Constructor Injection
- Action Injection using FromServices attribute.
- You can access additional settings by using options pattern instead of directly injecting IConfiguration inside the controller.
Comments
Post a Comment