ormsitecoreglass-mapper

GlassMapper Get Default Context V5


We recently updated to GlassMapper V5 (and also Sitecore 9) and our application is breaking almost everywhere.

I am not able to find enough documentation on this. I see that ISitecoreContext has become obsolete and we are asked to use IMvcContext, IRequestContext etc., but I don't know how to use them.

This is what I have currently and I am not sure how to get the default Sitecore context. It throws an error saying that

SitecoreContextFactory doesn't exist

My code:

   ILink link = SitecoreContextFactory.Default.GetSitecoreContext().GetItem<ILink>(SitecoreItems.StoreLocatorPage);

This is one such example. Can someone point me to the right documentation where I can find all replacement methods?


Solution

  • Documentation about upgrading to GlassMapper V5 with the replacement methods can be found here.

    You are absolutely right, SitecoreContext class has been marked as obsolete and from now on you should be using the new context offers:

    Both contexts use SitecoreService for communication with Sitecore.