2010-03-18 126 views
6

我已經從VS2008和MVC1更新了項目到VS2010和MVC2。我在與Ninject不會領域內找到控制器問題Ninject 2和MVC 2.0

這裏是我的global.asax.cs文件:

namespace Website 
{ 
// Note: For instructions on enabling IIS6 or IIS7 classic mode, 
// visit http://go.microsoft.com/?LinkId=9394801 

public class MvcApplication : NinjectHttpApplication 
{ 
    public static StandardKernel NinjectKernel; 

    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      "Balance", 
      "Balance/{action}/{month}/{year}", 
      new { controller = "Balance", action = "Index", month = DateTime.Now.Month, year = DateTime.Now.Year } 
     ); 

     routes.MapRoute(
      "Default",            // Route name 
      "{controller}/{action}/{id}",       // URL with parameters 
      new { controller = "Login", action = "Index", id = "" } // Parameter defaults 
     ); 

    } 

    /* 
    protected void Application_Start() 
    { 
     AreaRegistration.RegisterAllAreas(); 

     RegisterRoutes(RouteTable.Routes); 

     // initializes the NHProfiler so you can see what is going on with your queries 
     HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize(); 
    } 
    */ 

    protected override void OnApplicationStarted() 
    { 
     RegisterRoutes(RouteTable.Routes); 
     AreaRegistration.RegisterAllAreas(); 
     RegisterAllControllersIn(Assembly.GetExecutingAssembly()); 
    } 

    protected void Application_Error(object sender, EventArgs e) 
    { 
     var errorService = NinjectKernel.Get<IErrorLogService>(); 
     errorService.LogError(HttpContext.Current.Server.GetLastError().GetBaseException(), "AppSite"); 
    } 

    protected override IKernel CreateKernel() 
    { 
     if (NinjectKernel == null) 
     { 
      NinjectKernel = new StandardKernel(new ServiceModule()); 
     } 

     return NinjectKernel; 
    } 
} 

public class ServiceModule : NinjectModule 
{ 
    public override void Load() 
    { 
     Bind<IHelper>().To<Helper>().InRequestScope(); 
     Bind<IErrorLogService>().To<ErrorLogService>(); 

     Bind<INHSessionFactory>().To<NHSessionFactory>().InSingletonScope(); 
     Bind<ISessionFactory>().ToMethod(ctx => 
             ctx.Kernel.Get<INHSessionFactory>().GetSessionFactory()) 
           .InSingletonScope(); 

     Bind<INHSession>().To<NHSession>(); 
     Bind<ISession>().ToMethod(ctx => ctx.Kernel.Get<INHSession>().GetSession()); 
    } 
} 
} 

訪問/ Controllers文件夾工程確定內控制器,但內訪問控制器/地區/會員/控制器引發以下錯誤:

Server Error in '/' Application. 

Cannot be null 
Parameter name: service 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: Cannot be null 
Parameter name: service 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 
[ArgumentNullException: Cannot be null 
Parameter name: service] 
Ninject.ResolutionExtensions.GetResolutionIterator(IResolutionRoot root, Type service, Func`2 constraint, IEnumerable`1 parameters, Boolean isOptional, Boolean isUnique) +193 
Ninject.Web.Mvc.NinjectControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +41 
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +66 
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +124 
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50 
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48 
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16 
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8771488 
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 

Version Information: Microsoft .NET Framework Version:4.0.30128; ASP.NET  Version:4.0.30128.1 

的URL,此請求/會員/控制/,如果我更改URL太/控制器控制器大火,但我得到一個錯誤,該系統無法找到在路徑中查看/查看

當它應該是在尋找/地區/會員/瀏覽次數

我要麼做錯了升級或者我失去了一些東西BT我無法弄清楚。我一直在試圖算出這個3天......從核心

+0

我使用溫莎城堡得到同樣的錯誤。 – 2010-03-19 14:06:43

+0

@Carles很高興知道它不只是我 – 2010-03-19 21:52:56

+0

你應該能夠在NinjectControllerFactory.GetControllerInstance上設置一個斷點,你可以仔細檢查請求URL並報告回來嗎? – 2010-03-22 04:19:43

回答

1

更新,我只是犯了修復:http://github.com/ninject/ninject.web.mvc

-Ian

+0

@Ian謝謝你,我會試着在本週末檢查一下,如果我能找到一些時間的話。 – 2010-03-27 15:06:38

+0

正確的鏈接是http://github.com/ninject/ninject.web.mvc -sorry我無法編輯。 – 2010-06-29 18:32:58