Create a gist now

Instantly share code, notes, and snippets.

SingleAction Windsor Controller Factory
public class WindsorControllerFactory : DefaultControllerFactory
{
private readonly IKernel kernel;
public WindsorControllerFactory(IKernel kernel)
{
this.kernel = kernel;
}
public override void ReleaseController(IController controller)
{
kernel.ReleaseComponent(controller);
}
protected override IController GetControllerInstance(RequestContext context, Type controllerType)
{
var baseNs = typeof(SecureController).Namespace;
var ns = context.RouteData.GetRequiredString("controller").ToLower();
var controllerName = context.RouteData.GetRequiredString("action").ToLower() + "controller";
try
{
var controller = kernel.Resolve<IController>(baseNs.ToLower() + "." + ns + "." + controllerName);
return controller;
}
catch (ComponentNotFoundException ex)
{
throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", context.HttpContext.Request.Path));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment