Skip to content

Instantly share code, notes, and snippets.

@chaliy
Created October 13, 2011 21:00
Show Gist options
  • Select an option

  • Save chaliy/1285513 to your computer and use it in GitHub Desktop.

Select an option

Save chaliy/1285513 to your computer and use it in GitHub Desktop.
/// <summary>
/// Controller Factory class for instantiating controllers using the Windsor IoC container.
/// </summary>
public sealed class WindsorControllerFactory : DefaultControllerFactory
{
private readonly IWindsorContainer _container;
/// <summary>
/// Creates a new instance of the <see cref="WindsorControllerFactory"/> class.
/// </summary>
/// <param name="container">The Windsor container instance to use when creating controllers.</param>
public WindsorControllerFactory(IWindsorContainer container)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
_container = container;
}
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
{
throw new HttpException(404, "The resourse could not be found");
}
return (IController)_container.Resolve(controllerType);
}
public override void ReleaseController(IController controller)
{
base.ReleaseController(controller);
_container.Release(controller);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment