ASP.Net MVC3 : Steven Sanderson's tutorial — using Ninject error [closed]

梦想的初衷 提交于 2019-12-13 22:35:27

问题


My project errors with the global.asax Application_Start calls: ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());

namespace SportsStore.WebUI.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory 
    {
        private IKernel ninjectKernel;

        public NinjectControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController)ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {
            // put additional bindingers here
        }
    }

ERROR STACK:

Locating source for 'c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Multimap.cs'. 
Checksum: MD5 {de 1d cc 43 b7 22 44 a5 8d 8b 50 ed 23 dc 4 28} 
The file 'c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Multimap.cs' does not exist. 
Looking in script documents for 'c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Multimap.cs'... 
Looking in the projects for 'c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Multimap.cs'. 
The file was not found in a project. Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\'... 
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc\'... 
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfcsrc\atl\'...
Looking in directory 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\'... 
The debugger will ask the user to find the file: c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Multimap.cs. 
The user pressed Cancel in the Find Source dialog. 
The debug source files settings for the active solution have been modified so that the debugger will not ask the user to find the file: c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Multimap.cs. 
The debugger could not locate the source file 'c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Infrastructure\Multimap.cs'.

回答1:


I suggest to use the official Ninject MVC3 extension. The NuGet package Ninject.MVC3 will setup everything for you so that you can start to inject depenencies into your controllers.

Replacing the controller factory isn't the prefered way anymore for MVC3. With this release the proposed approch by the MVC development team is to use a DependencyResolver instead. The Ninject MVC3 extension uses this approach.

Read the documentation at https://github.com/ninject/ninject.web.mvc/wiki/MVC3 for more information.



来源:https://stackoverflow.com/questions/7271839/asp-net-mvc3-steven-sandersons-tutorial-using-ninject-error

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