Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 542 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query Orchard CMS from IShapeFactoryEvents

#1
I am trying to insert shapes into my layout from my module once it has been enabled. I figured IShapeFactoryEvents would be perfect for this, but querying the CMS from here gives me a "TransactionScope nested incorrectly exception" if this occurs during a POST. Wondering if anyone had any words of wisdom for me again? See my code snippet below.

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");
}
}
}

Once again, thanks in advance. You guys are awesome.
Reply

#2
See the blog post I did on this very topic here:

[To see links please register here]


From the blog post:
>"One thing I need to note, and this took me an entire day to discover, is that you can't just inject your data service into your IShapeTableProvider implementation. If you do, it'll try to use a transaction out of scope and that will cause you all kinds of problems. After tearing my hair out for hours on end, I finally discovered what the Orchard team is doing inside of the CoreShapes class: The trick to resolve a service dependency within the function itself by using a property that loads the service per-request."

Try using your service like this instead:


private IOrchardServices Services
{
get
{
return _workContextAccessor.GetContext(_httpContextAccessor.Current()).Resolve<IOrchardServices>();
}
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through