C# GetContextItem<&燃气轮机;()始终为空
在以下代码中,此行始终返回null:C# GetContextItem<&燃气轮机;()始终为空,c#,.net,sitecore,glass-mapper,C#,.net,Sitecore,Glass Mapper,在以下代码中,此行始终返回null: var datasource = GetContextItem<IGlassBase>(inferType: true); var-datasource=GetContextItem(推断类型:true); 这是一节课: using System.Web.Mvc; using Jabberwocky.Glass.Models; using CCO.Feature.Global.Services; using CCO.Foundation.Mu
var datasource = GetContextItem<IGlassBase>(inferType: true);
var-datasource=GetContextItem(推断类型:true);
这是一节课:
using System.Web.Mvc;
using Jabberwocky.Glass.Models;
using CCO.Feature.Global.Services;
using CCO.Foundation.Multisite.Configuration;
using CCO.Foundation.Mvc.Controllers;
using Jabberwocky.Autofac.Attributes;
namespace CCO.Feature.Global.Areas.CCO.Controllers
{
public class MetadataController : CCOController
{
[AggregateService]
public interface IDependencies
{
IMetadataService MetadataService { get; set; }
ISitecoreConfigurationManager SitecoreConfigurationManager { get; set; }
}
private readonly IDependencies _dependencies;
public MetadataController(IDependencies dependencies) : base(dependencies?.SitecoreConfigurationManager)
{
_dependencies = dependencies;
}
public MetadataController() : base() { }
public virtual ActionResult HtmlPageTitle()
{
var datasource = GetContextItem<IGlassBase>(inferType: true);
var title = _dependencies.MetadataService.GetHtmlPageTitle(datasource);
return View(new MvcHtmlString(title));
}
public virtual ActionResult Metadata()
{
var datasource = GetContextItem<IGlassBase>(inferType: true);
var model = _dependencies.MetadataService.GetPageMetadata(datasource);
return View(model);
}
public ActionResult CustomHeadHtml()
{
var datasource = GetContextItem<IGlassBase>(inferType: true);
var html = _dependencies.MetadataService.GetCustomHeadHtml(datasource);
return View(new MvcHtmlString(html));
}
}
}
使用System.Web.Mvc;
使用Jabberwocky.Glass.Models;
使用CCO.Feature.Global.Services;
使用CCO.基础.多站点配置;
使用CCO.Fuff.MVC.控制器;
使用Jabberwocky.Autofac.Attributes;
命名空间CCO.Feature.Global.Areas.CCO.Controllers
{
公共类MetadataController:CCOController
{
[聚合服务]
公共接口独立性
{
IMetadataService MetadataService{get;set;}
ISitecoreConfigurationManager站点CoreConfigurationManager{get;set;}
}
私有只读IDependencies _依赖项;
公共MetadataController(IDependencies依赖项):基本(依赖项?.SitecoreConfigurationManager)
{
_依赖关系=依赖关系;
}
公共MetadataController():base(){}
公共虚拟操作结果HTMLPGETITLE()
{
var datasource=GetContextItem(推断类型:true);
var title=_dependencies.MetadataService.GetHtmlPageTitle(数据源);
返回视图(新的MvcHtmlString(title));
}
公共虚拟操作结果元数据()
{
var datasource=GetContextItem(推断类型:true);
var model=_dependencies.MetadataService.GetPageMetadata(数据源);
返回视图(模型);
}
公共操作结果CustomHeadHtml()
{
var datasource=GetContextItem(推断类型:true);
var html=_dependencies.MetadataService.GetCustomHeadHtml(数据源);
返回视图(新的MvcHtmlString(html));
}
}
}
在将GlassMapper更新为4.5.0.4和将Jabberwocky更新为3.0.0之前,这是可行的。当我们从Sitecore 8.2升级到9.1时,这些升级是必需的。根本不需要无参数构造函数。如果您遇到这样的错误,通常意味着您的依赖项注入不适用于Sitecore控制器。除非您手动注册每个控制器(不太可能),否则您应该只拥有要调用的构造函数 您可以在以下URL查看依赖项注入的详细信息: 如果您没有使用默认的
serviceProviderBuilder
(例如,如果您使用的是AutoFac或其他东西),那么您的配置中应该显示一个自定义生成器
有关更多信息,请参见,根本不需要无参数构造函数。如果您遇到这样的错误,通常意味着您的依赖项注入不适用于Sitecore控制器。除非您手动注册每个控制器(不太可能),否则您应该只拥有要调用的构造函数 您可以在以下URL查看依赖项注入的详细信息: 如果您没有使用默认的
serviceProviderBuilder
(例如,如果您使用的是AutoFac或其他东西),那么您的配置中应该显示一个自定义生成器
有关更多信息,请参见看起来布局正在调用无参数构造函数,而不是初始化依赖项的构造函数。在我们的Sitecore 8.2代码中,上述类中不需要无参数构造函数。在地狱里我该如何解决这个问题呢?看起来布局调用的是无参数构造函数,而不是初始化依赖项的构造函数。在我们的Sitecore 8.2代码中,上述类中不需要无参数构造函数。在地狱里我该如何解决这个问题?这个问题通过Sitecore支持得到了解决。我们现在遇到的问题是,我们必须升级到Glass.Mapper 5.0,现在Jabberwocky与新版本的Glass集成时出现问题。Jabberwocky似乎正在调用Glass V5中不再存在的方法,并抛出运行时错误。任何建议都会有帮助。此问题已通过Sitecore支持解决。我们现在遇到的问题是,我们必须升级到Glass.Mapper 5.0,现在Jabberwocky与新版本的Glass集成时出现问题。Jabberwocky似乎正在调用Glass V5中不再存在的方法,并抛出运行时错误。任何建议都会有帮助。