我的项目错误与global.asax Application_Start调用: 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
}
}
错误堆叠:
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'.
答案 0 :(得分:9)
我建议使用官方的Ninject MVC3扩展。 NuGet软件包Ninject.MVC3将为您设置所有内容,以便您可以开始将依赖项注入控制器。
更换控制器工厂不再是MVC3的首选方式。在此版本中,MVC开发团队提出的建议是使用DependencyResolver。 Ninject MVC3扩展使用了这种方法。
请阅读https://github.com/ninject/ninject.web.mvc/wiki/MVC3处的文档以获取更多信息。