How do I work with Ninject in an ASP.NET MVC Web App?

后端 未结 3 1534
别那么骄傲
别那么骄傲 2021-02-12 03:54

I\'ve created a new MVC Web application and I have references to Ninject.dll, Ninject.Web.Common.dll and Ninject.Web.MVC.dll.

Global.asax.cs:

         


        
3条回答
  •  被撕碎了的回忆
    2021-02-12 04:24

    To be explicitly clear about this, if you use NuGet to add the 'Ninject.Mvc3' package (I used version 3.0.0.6), there is no need to make any modifications to global.asax.cs. The NuGet package does the magic for you by creating the NinjectWebCommon class in the App_Start folder of your MVC 4 project.

    I say this because I seem to have followed a similar tutorial to the original poster (I followed an article on The Code Project called 'Dependency Injection in asp.net mvc4 and webapi using Ninject'), and had exactly the same issue as the original poster. The Code Project article doesn't make it clear that you should either use NuGet (and don't touch global.asax.cs or add the Ninject references manually (and amend global.asax.cs).

提交回复
热议问题