c# - Glass.Mapper.Sc 默认全局设置 inferType 为 true

标签 c# sitecore glass-mapper

在 Glass.Mapper.Sc v 4.0.1.5 中,ISitecoreService 和 ISitecoreContext 的所有方法签名的 inferType 默认为 false。 我正在寻找一种方法来覆盖它并默认为 true,而无需更改整个站点的方法调用。

我创建了另一个接口(interface)来覆盖那些只是为了将 inferType 默认值修改为 true 但我想知道是否有更好的解决方案。

最佳答案

没有自动覆盖来执行此操作,但在配置解析器管道中创建您自己的任务可能更简单。

如果您查看以下代码行: https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/Pipelines/ConfigurationResolver/TemplateInferredTypeTask.cs#L48

您可以看到它只检查 InferType 标志,您可以在请求开始时创建另一个管道,将其设置为 true。然后每个请求都将通过 InferType 强制执行。

您需要使用 Add 方法在 GlassMapperScCustom 中针对 DependencyResolver.ConfigurationResolverFactory 注册您的新管道进程。

关于c# - Glass.Mapper.Sc 默认全局设置 inferType 为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30468728/

相关文章:

c# - Windows Phone 8.1 中的设备状态

sitecore - 缺少所需的许可证 : Runtime Sitecore

reporting - Sitecore Analytics 报告匿名用户与成员

c# - 在代码中从 C# 调用网页

c# - 复制 Win7 网络弹出刷新按钮

javascript - 从对话框中获取值并在后面的代码中使用它们

content-management-system - 配置 sitecore 站点

c# - 玻璃映射器渲染图像数据属性

asp.net-mvc - 使用 glassmapper 在 Sitecore MVC 中重用多个模型的 View

Sitecore:Glass Mapper 代码优先