Skip to content

Instantly share code, notes, and snippets.

@Itslet
Created March 10, 2011 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Itslet/864832 to your computer and use it in GitHub Desktop.
Save Itslet/864832 to your computer and use it in GitHub Desktop.
using Castle;
using Castle.MicroKernel;
using System.Web.Mvc;
using System.Web.Routing;
namespace CastleDemo.Plumbing
{
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 requestContext, Type controllerType)
{
if (controllerType == null)
{
throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path));
}
return (IController)kernel.Resolve(controllerType);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment