在 Simple Injector Sitecore 8.1 MVC 中找不到类型 'CommonController' 的构造函数问题

Constructor on type 'CommonController' not found issue in Simple Injector Sitecore 8.1 MVC

我已经在 Sitecore 8.1 MVC glass mapper v4 项目中实现了 Simple Injector,并在 MVC 上使用了 Controller 渲染 Layout.When 我 运行 页面出现以下错误:

Server Error in '/' Application.

Constructor on type 'GlassSimpleInjector.Controllers.CommonController' not found. 
  Description: An unhandled exception occurred. 

 Exception Details: System.MissingMethodException: Constructor on type 'GlassSimpleInjector.Controllers.CommonController' not found.

Source Error: 



Line 13:         <h1>@Html.Sitecore().Field("title")</h1>
Line 14:         <div>
Line 15:             @Html.Sitecore().Placeholder("main")
Line 16:         </div>
Line 17:     </body>


 Source File:  c:\inetpub\wwwroot\GlassSimpleInjector\Website\Views\Shared\MVC Layout.cshtml    Line:  15 

Stack Trace: 



[MissingMethodException: Constructor on type 'GlassSimpleInjector.Controllers.CommonController' not found.]
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) +14259449
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +200
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +28
   Sitecore.Mvc.Helpers.TypeHelper.CreateObject(Type type, Object[] parameters) +43
   Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateControllerInstance(RequestContext requestContext, String controllerName) +330
   Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName) +122

[ControllerCreationException: Could not create controller: ' GlassSimpleInjector.Controllers.CommonController,GlassSimpleInjector'. 
The context item is: '/sitecore/content/Home'. 
The current route url is: '{*pathInfo}'. This is the default Sitecore route which is set up in the 'InitializeRoutes' processor of the 'initialize' pipeline. ]
   Sitecore.Mvc.Controllers.SitecoreControllerFactory.CreateController(RequestContext requestContext, String controllerName) +371
   Sitecore.Mvc.Controllers.ControllerRunner.GetController() +24
   Sitecore.Mvc.Controllers.ControllerRunner.Execute() +54
   Sitecore.Mvc.Presentation.ControllerRenderer.Render(TextWriter writer) +131
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Render(Renderer renderer, TextWriter writer, RenderRenderingArgs args) +27
   Sitecore.Mvc.Pipelines.Response.RenderRendering.ExecuteRenderer.Process(RenderRenderingArgs args) +62
   (Object , Object[] ) +83
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +369
   Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +202
   Sitecore.Mvc.Pipelines.Response.RenderPlaceholder.PerformRendering.Render(String placeholderName, TextWriter writer, RenderPlaceholderArgs args) +192
   (Object , Object[] ) +83
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +369
   Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +202
   Sitecore.Mvc.Helpers.SitecoreHelper.Placeholder(String placeholderName) +323
   ASP._Page_Views_Shared_MVC_Layout_cshtml.Execute() in c:\inetpub\wwwroot\GlassSimpleInjector\Website\Views\Shared\MVC Layout.cshtml:15
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +125
   System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +147
   Sitecore.Mvc.Presentation.ViewRenderer.Render(TextWriter writer) +258

我几乎完成了所有配置,但不知道缺少什么。 任何建议。 我已经实现了这个 link

的解决方案

Simple Injector

更新于 2015 年 11 月 24 日

只是想了解一下结构 我有两个 MVC 项目:

GlassSimpleInjector.Global -->我在这里做了基本的 SimpleInjector 实现,并在 App_Start 文件夹中添加了 SimpleInjector.cs class,其中包含通用功能和注册的 ISitecoreService 和 ISitecoreContext

GlassSimpleInjector --> 我在 App_Start 中添加了 SimpleInjector.cs 文件,我在其中注册了接口,class 仅针对此项目

SimpleInjector.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
               xmlns:set="http://www.sitecore.net/xmlconfig/set/">>
  <sitecore>
    <pipelines>
      <initialize>
        <processor type="Sitecore.Mvc.Pipelines.Loader.InitializeControllerFactory, Sitecore.Mvc"
                   set:type="GlassSimpleInjector.Global.Pipelines.DI.InitializeSimpleInjectorControllerFactory, GlassSimpleInjector.Global" />
      </initialize>
    </pipelines>
  </sitecore>
</configuration>

您确定您的控制器工厂正在注册吗?根据堆栈跟踪,未调用 SimpleInjectorControllerFactory。尝试检查 showConfig 页面以查看您的处理器是否已正确修补到初始化管道中。

更新以回应 OP

的评论

Akshay post 中的第一段代码是 Sitecore 配置补丁文件,需要放在 /App_Config/Include 文件夹中。请注意,您需要将它放在一个额外的子文件夹中或命名该文件,以便它按字母顺序排在 Sitecore.Mvc.config 之后,以便正确修补原始处理器。如果您在浏览器中转到 /sitecore/admin/showconfig.aspx,您可以看到合并后的配置。您应该会在 initialize 管道中的原始 InitializeControllerFactory 处理器位置看到自定义处理器。如果它不存在,那么您的控制器工厂将不会注册。

更新 问题是配置补丁文件中多了一个右尖括号。