How to avoid redundant DI code in ASP.NET Core
When working with controllers in web applications using ASP.NET Core or ASP.NET Core MVC, you might have encountered code redundancy. For example, you might have come across controllers that use dependency injection (DI) to inject services that they need. If the code that injects the dependencies has been reused in multiple controllers, then you have code redundancy and violation of the DRY principle (don’t repeat yourself).This article looks at DI code redundancy and shows how to build your custom base controller to avoid such issues. To work with the code examples provided in this article, you should have Visual Studio 2019 installed in your system. If you don’t already have a copy, you can download Visual Studio 2019 here.To read this article in full, please click here
When working with controllers in web applications using ASP.NET Core or ASP.NET Core MVC, you might have encountered code redundancy. For example, you might have come across controllers that use dependency injection (DI) to inject services that they need. If the code that injects the dependencies has been reused in multiple controllers, then you have code redundancy and violation of the DRY principle (don’t repeat yourself).
This article looks at DI code redundancy and shows how to build your custom base controller to avoid such issues. To work with the code examples provided in this article, you should have Visual Studio 2019 installed in your system. If you don’t already have a copy, you can download Visual Studio 2019 here.