ASP.NET MVC 5 Ninject: Ninject.MVC3/5

早过忘川 提交于 2019-12-11 04:06:53

问题


I want to add Ninject to an ASP.NET MVC 5 Project.

NinjectWebCommon.cs is not in the App_Start folder. In a tutorial I read that Ninject.MVC3 should be added via Nuget.

If I go into 'Manag NuGet Packages' and search for 'Ninject' I get the following:

There I find 'Ninject.MVC5'. A symbol indicates that this package is installed.

But when I go to 'Installed packages' I see the following:

Here I cannot find this package.

Why is the package not listed here?

Should I install 'Ninject.MVC3' although 'Ninject.MVC5' seems to be installed?


Edit:


I have now installed the NuGet Package via the Package Manager Console like the following:

Each package is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Some packages may include dependencies which are governed by additional licenses. Follow the package source (feed) URL to determine any dependencies.

Package Manager Console Host Version 2.8.50926.663

Type 'get-help NuGet' to see all available NuGet commands.

PM> Install-Package Ninject.MVC5
Attempting to resolve dependency 'Ninject (≥ 3.2.0.0 && < 3.3.0.0)'.
Attempting to resolve dependency 'Ninject.Web.Common.WebHost (≥ 3.0.0.0)'.
Attempting to resolve dependency 'Ninject.Web.Common (≥ 3.2.0.0 && < 3.3.0.0)'.
Attempting to resolve dependency 'WebActivatorEx (≥ 2.0 && < 3.0)'.
Attempting to resolve dependency 'Microsoft.Web.Infrastructure (≥ 1.0.0.0)'.
'Ninject.MVC5 3.2.1.0' already installed.
Adding 'WebActivatorEx 2.0' to WebApplication.
Successfully added 'WebActivatorEx 2.0' to WebApplication.
Adding 'Ninject.Web.Common.WebHost 3.2.0.0' to WebApplication.
Successfully added 'Ninject.Web.Common.WebHost 3.2.0.0' to WebApplication.
Adding 'Ninject.MVC5 3.2.1.0' to WebApplication.
Successfully added 'Ninject.MVC5 3.2.1.0' to WebApplication.

It says that Ninject.MVC5 is already installed but adds the necessary files to the ASP.NET MVC Project anyways.

Now the Package also is under Installes Packages:

This way I can go on and use Ninject in my project. Though, I still do not really understand what happened here. Why where the files not in my ASP.NET MVC project? Why did Visual Studio state that the package was installed, but why was it not under installed packages? Is there a reason for this or is this a software bug?


回答1:


go to package.config and delete lines with 'ninject'.after that reinstall ninject from NuGet Package via the Package Manager Console.




回答2:


Try Install-Package Ninject.MVC5 or Ninject.MVC3. For my case its MVC5.




回答3:


Install-Package Ninject -version 3.0.1.10 Install-Package Ninject.Web.Comon -version 3.0.0.7 Install-Package Ninject.MV3 -version 3.0.0.6



来源:https://stackoverflow.com/questions/28098981/asp-net-mvc-5-ninject-ninject-mvc3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!