Lifestyle bindings for .NET providers in Sitecore with Castle Windsor

When I first set up our delivery servers I was finding random entries in the log files (which I stupidly haven't saved) saying that the role provider was throwing an error. The solution to this was a simple one, Sitecore was calling the role provider on the delivery server where a server Request didn't exist.

To resolve Session issues I had set the lifestyle for resolving ISession to be PerWebRequest() rather than Transient. This fixed the Session issues (ISession is closed!, really helpful error messages there) but meant the required dependencies weren't being resolved outside of the request. So what do you need to do? Install the Castle.Windsor.Lifestyles packed and set your ISession to resolve using the HybridPerWebRequestTransient() lifestyle.

Component.For<ISession>() .UsingFactoryMethod(OpenSession) .LifeStyle.HybridPerWebRequestTransient());