Sitecore Upgrade to 10 - Glass.Mapper 5 and Windsor

Sitecore Upgrade to 10 - Glass.Mapper 5 and Windsor

By admin May 14, 2024

If you use WindsorContainer and upgrading Glass Mapper to 5, you need to change the registration to the container

 public class ContextInstaller : IWindsorInstaller
 {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
             container.Register(
                Component.For<IRequestContext>().ImplementedBy<RequestContext>().LifestylePerWebRequest(),
                Component.For<IMvcContext>().ImplementedBy<MvcContext>().LifestylePerWebRequest(),
                Component.For<IWebFormsContext>().ImplementedBy<WebFormsContext>().LifestylePerWebRequest(),
                );
        }
}

The GlassMapperScCustom need to be extended to install the ContextInstaller. This should be done in CreateResolver() method

var container = new Castle.Windsor.WindsorContainer();
container.Install(new ContextInstaller());
GlobalConfiguration.Configuration.Services.Replace(typeof(System.Web.Http.Dispatcher.IHttpControllerActivator),
               new WindowsControllerActivator(container));
           System.Web.Mvc.ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container.Kernel));

For more information upgrading Sitecore, see this post.

How to upgrade GlassMapper is described in this post. However, here is the official page.

Featured Blogs