Created
August 15, 2016 12:26
-
-
Save cassidydotdk/519dee612ca4683a18303298a429715c to your computer and use it in GitHub Desktop.
Controller Factory Handling - Sitecore 8.1 and Castle Windsor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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