2
我试图从我的模块插入形状到我的布局,一旦它已被启用。我认为IShapeFactoryEvents对于这一点来说是完美的,但是如果在POST期间发生这种情况,则从这里查询CMS会给我一个“TransactionScope嵌套错误异常”。想知道是否有人再次对我有任何智慧话语?看到我下面的代码片段。从IShapeFactoryEvents查询Orchard CMS
public void Created(ShapeCreatedContext context)
{
if (context.ShapeType == "Layout")
{
if (!AdminFilter.IsApplied(_services.WorkContext.HttpContext.Request.RequestContext))
{
var route = RouteTable.Routes.GetRouteData(_services.WorkContext.HttpContext);
object location;
if (route.Values.TryGetValue("location", out location))
{
var region = _services.ContentManager.Query("Region")
.Join<RoutePartRecord>()
.Where(x => x.Slug == (string)location)
.Slice(1).FirstOrDefault();
context.Shape.Header.Add(context.New.CurrentRegion(Title: region.As<RoutePart>().Title), "10");
}
context.Shape.Navigation.Add(context.New.RegionSelector(Regions: _services.ContentManager.Query(VersionOptions.Published, "Region").List()), "11");
}
}
}
再次,在此先感谢。你们真棒。
感谢@克里斯 - 鲍尔,工作一种享受。你的网站进展如何?它在生产吗? – Brendan
@Brendan - 是的,我们在六月发布了它:[aclj.org](http://aclj.org) –
@Chris另一种解决方案是将'Work'而不是'T'注入'IShapeTableProvider'实现构造函数。然后,您可以通过'Work '的'Value'属性访问底层对象。它返回适合当前上下文的实例。当您需要将每个请求依赖项注入单例依赖项时,这是有用的。 –