I am a Castle Winsor Noob. I have a WebForm project that is a hot mess. I am trying to resolve a dependency to test user registration. How do I get to the current Windsor
There is interface in Windsor for this purpose. It is called IContainerAccessor. Best place to implement it is the Global.asax file:
public class WebApplication : HttpApplication, IContainerAccessor {
static IWindsorContainer container;
public IWindsorContainer Container {
get { return container; }
}
protected void Application_Start() {
var bootstrapper = new WindsorConfigTask();
bootstrapper.Execute();
container = bootstrapper.Container;
}
protected void Application_End() {
container.Dispose();
}
}
The usage in your web form is as following:
var containerAccessor = Context.ApplicationInstance as IContainerAccessor;
var container = containerAccessor.Container;