Created
October 13, 2011 21:00
-
-
Save chaliy/1285513 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /// <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