2012-07-28 4 views
0

종속성 주입 프레임 워크로 Ninject를 사용하여 ASP.NET MVC 3.0 응용 프로그램에서 작업하고 있습니다."리소스를 찾을 수 없습니다." Ninject를 사용할 때 오류가 발생했습니다.

public class MvcApplication : NinjectHttpApplication 
{ 
    protected override void OnApplicationStarted() 
    { 
     base.OnApplicationStarted(); 
    } 

    protected void Application_Start() 
    { 
     RegisterGlobalFilters(GlobalFilters.Filters); 
     RegisterRoutes(RouteTable.Routes); 
     AreaRegistration.RegisterAllAreas(); 
     DependencyResolver.SetResolver(new NinjectDependencyResolver(Kernel)); 
    } 

    protected override Ninject.IKernel CreateKernel() 
    { 
     return new StandardKernel(new QueriesModule()); 
    } 

    public static void RegisterGlobalFilters(GlobalFilterCollection filters) 
    { 
     filters.Add(new HandleErrorAttribute()); 
    } 

    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.MapRoute(
      "Default", 
      "{controller}/{action}", 
      new { controller = "Home", action = "Index" }, 
      new string[] { typeof(HomeController).Namespace } 
     ); 
    } 
} 

을하지만 응용 프로그램을 실행하고 내 컨트롤러 중 하나에 탐색하려고 할 때마다, 나는 오류 얻을 :

그래서 나는과 같이 NinjectHttpApplication에서 내 컨트롤러를 상속 한

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Home/Index

이 문제의 원인은 무엇이며 어떻게 수정합니까?

답변

1

내가 상속 받고있는 NinjectHttpApplication 클래스가 시작시 OnApplicationStarted() 메서드를 호출하기 때문에이 문제가 발생했다. 그래서 해결책은 Application_Start() 메소드를 제거하고 모든 코드를 OnApplicationStarted()으로 옮기는 것입니다.

관련 문제