How to create dependency injection for ASP.NET MVC 5?

前端 未结 9 1740
挽巷
挽巷 2020-12-23 03:08

Creating Dependency Injection with ASP.NET Core is fairly easy. The documentation explains it very well here and this guy has a killer video to explain it.

However,

9条回答
  •  旧时难觅i
    2020-12-23 03:54

    The simplest way to implements Dependency Injection in ASP.NET MVC 5 is to use the tool developed by Microsoft itself, called Unity.

    You can find many resources on the internet about it, and you can start by reading the official documentation available here: Developer's Guide to Dependency Injection Using Unity

    Also, is Dependency injection limited to controllers only or can it work with any class?

    It works with any class, in any project, as long as you register the Interface related to the Implementation (if you want to take profit of the IoC pattern), all you have to do then is to add the Interface instantiation in your constructor.

提交回复
热议问题