本文介绍了Ninject错误:他IControllerFactory“Ninject.Web.Mvc.NinjectControllerFactory”没有为名称'产品'返回控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的死亡以下黄屏的IControllerFactory'Ninject.Web.Mvc.NinjectControllerFactory'的名称为产品未返回的控制器。为什么?这里是我的设置

更新
这种配置我的电脑上,但不是我同事的电脑上,即使我们的计算机具有相同的code和配置。

code

 公共类MvcApplication:NinjectHttpApplication
    {
        公共静态无效的RegisterRoutes(RouteCollection路线)
        {
            routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);            routes.MapRoute(
                默认,//路线名称
                {控制器} / {行动} / {ID},// URL带参数
                新{控制器=产品,行动=索引,ID = UrlParameter.Optional} //参数默认
            );        }        保护覆盖无效OnApplicationStarted()
        {
            的RegisterRoutes(RouteTable.Routes);
            RegisterAllControllersIn(Assembly.GetExecutingAssembly());
        }        保护覆盖的iKernel CreateKernel()
        {
            VAR模块=新INinjectModule []
                        {
                            新WebModule()
                        };            返回新StandardKernel(模块);
        }
    }公共类WebModule:NinjectModule
    {
        公共覆盖无效负载()
        {
            绑定< IAuthoringRepository>()
                .ToProvider(新AuthoringProvider())
                .InSingletonScope();            绑定< ICatalogEntity>()
                .ToProvider(新ProductProvider())
                .InSingletonScope();            绑定< TargetData>()
                。.ToProvider(新TargetDataProvider())InSingletonScope();
        }
    }    公共类AuthoringProvider:提供< IAuthoringRepository> {
        保护覆盖IAuthoringRepository的CreateInstance(IContext上下文)
        {
            的WindowsIdentity同一性= WindowsIdentity.GetCurrent();
            IAuthoringRepository结果= RepositoryFactory.CreateAuthoringRepository(身份);
            返回结果;
        }
    }    公共类TargetDataProvider:提供< TargetData>
    {
        保护覆盖TargetData的CreateInstance(IContext上下文)
        {
            返回新TargetData {语言= Language.En,省= Province.ON};
        }
    }    公共类ProductProvider:提供<产品与GT;
    {
        保护覆盖产品的CreateInstance(IContext上下文)
        {
            返回新产品();
        }
    }

更多关于错误
该IControllerFactoryNinject.Web.Mvc.NinjectControllerFactory没有为名称'产品'返回的控制器。
说明:执行当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。

异常详细信息:

Source Error:

Stack Trace:

[InvalidOperationException: The IControllerFactory 'Ninject.Web.Mvc.NinjectControllerFactory' did not return a controller for the name 'Products'.]
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +365
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +160
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +80
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +45
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8837208
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
解决方案

Update to the latest Ninject.Web.Mvc and remove this line:

RegisterAllControllersIn(Assembly.GetExecutingAssembly());

The registration is no longer needed.

这篇关于Ninject错误:他IControllerFactory“Ninject.Web.Mvc.NinjectControllerFactory”没有为名称'产品'返回控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:02