Created
March 10, 2011 20:12
-
-
Save Itslet/864832 to your computer and use it in GitHub Desktop.
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 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