2011-09-01 3 views
-2

global.asax Application_Start 호출로 인한 프로젝트 오류 : ControllerBuilder.Current.SetControllerFactory (new NinjectControllerFactory());ASP.Net MVC3 : Stein Sanderson의 튜토리얼 - Ninject 오류 사용

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

그런데 WebUI 프로젝트의 Ninject 4.0 클라이언트에 대한 참조를 추가했습니다. – Susan

+0

Ninject.MVC3 Nuget 패키지를 사용해 보셨습니까? http://nuget.org/List/Packages/Ninject.MVC3/2.2.2.0 – Peter

+0

설치 절차를 따르셨습니까? 지금까지 내가 아는 한, Steven은 Ninject를 설치하고 즉시 참조 할 수있는 Install-Package Ninject -Project SportsStore.WebUI를 사용할 수있는 예제를 제공 했습니까? –

답변

9

나는 공식 Ninject에 MVC3 확장자를 사용하는 것이 좋습니다. NuGet 패키지 인 Ninject.MVC3는 당신을 위해 모든 것을 설정할 것이므로 컨트롤러에 종속성을 주입 할 수 있습니다.

컨트롤러 팩터를 교체하는 것이 MVC3에서 더 이상 권장되지 않습니다. 이 릴리스에서 MVC 개발 팀이 제안한 승인은 대신 DependencyResolver를 사용하는 것입니다. Ninject MVC3 확장은이 방법을 사용합니다.

자세한 내용은 https://github.com/ninject/ninject.web.mvc/wiki/MVC3의 설명서를 참조하십시오.

+0

바로 위에! 100 % ... 내 2 센트 :) 그럼 당신의 의존성을 별도의 프로젝트에 사용 모듈을 분리. – CrazyCoderz

+0

Ninject MVC3 확장을 시도했지만 여전히 ninjectKernel = new StandardKernel()이 null을 반환하고 동일한 문제가 발생했습니다. – Susan

+0

죄송합니다. 올바르게 끝내지 않았습니다. '개인 IKernel ninjectKernal 문이 NULL을 반환하고 ninjectKernel = new StandardKernel이 Multimap.cs를 찾습니다.' – Susan