Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Controller Factory Handling - Sitecore 8.1 and Castle Windsor
using System.Web.Mvc;
using Castle.Windsor;
using Sitecore.Mvc.Controllers;
using Sitecore.Mvc.Pipelines.Loader;
using Sitecore.Pipelines;
using Interfaces.Managers.Windsor;
using ControllerBuilder = System.Web.Mvc.ControllerBuilder;
namespace Website
{
public class InitializeWindsorSitecoreControllerFactory : InitializeControllerFactory
{
protected override void SetControllerFactory(PipelineArgs args)
{
base.SetControllerFactory(args);
ControllerBuilder.Current.SetControllerFactory(new WindsorSitecoreControllerFactory(ControllerBuilder.Current.GetControllerFactory()));
}
}
public class WindsorSitecoreControllerFactory : SitecoreControllerFactory
{
private readonly IWindsorContainer _container;
public WindsorSitecoreControllerFactory(IControllerFactory innerFactory) : base(innerFactory)
{
_container = ContainerManager.Current.Container;
}
public override void ReleaseController(IController controller)
{
_container.Release(controller);
base.ReleaseController(controller);
}
}
}
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<initialize>
<processor patch:instead="*[@type='Sitecore.Mvc.Pipelines.Loader.InitializeControllerFactory, Sitecore.Mvc']" type="Website.InitializeWindsorSitecoreControllerFactory, Website"/>
</initialize>
</pipelines>
</sitecore>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment