2020-12-08 22:09

GetModel load order


Just wanted to let you know of something we ran into with Glass.Mapper.Sc.

In Sitecore 8, we load all our customized (non-Out of the box) config files in through a folder called "Xtras". We do this to ensure all of our custom configs run last (Sitecore loads in .config files in alpha order). Thus if we're overriding any app settings or what not using custom configs, the Xtras folder ensures they load at the very end (due to the X in the name) -- I guess we could have used Z, but Xtras was what we went with). I can't remember if this tip came from John West or some other blog.

Anyway, when we put our Glass.Mapper.Sc.config into our Xtras folder, we get a weird issue in which the View Model isn't loaded with the data when using an View rendering using GlassView (the model exists but everything is null). But yet we could get the populated model if we did SitecoreContext.GetCurrentItem().

After some digging with dotPeek, I've determined that the GlassMapper getModel pipelines were running too late. If we weren't using the Xtras folder, by default they would run first because "Glass.Mapper.Sc.config" comes before "Sitecore.Mvc.config" in alpha order. But using our Xtras folder, we buggered this up and they ended up running after the other Sitecore.Mvc.getModel pipelines. (this was confirmed using ShowConfig.aspx, and reviewing the order of the processors).

Thus the GlassMapper getModel was always exiting out on the first line when it hit this piece of code: if (args.Result != null) return;

Because one of the Sitecore processors was populating args.Result.

We made the following changes and it seems to have fixed the issue. Not sure if this kind of approach should be added into the source. It seems like the getChromeData processor was patched in a specific order, yet the getModel processors weren't.


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享