Castle Windsor Controller Factory and RenderAction

Posted by Bradley Landis on Stack Overflow See other posts from Stack Overflow or by Bradley Landis
Published on 2010-05-06T22:04:38Z Indexed on 2010/05/06 22:08 UTC
Read the original article Hit count: 229

I am running into an issue when using my Castle Windsor Controller Factory with the new RenderAction method. I get the following error message:

A single instance of controller 'MyController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request.

This is the code in my controller factory:

public class CastleWindsorControllerFactory : DefaultControllerFactory
    {
        private IWindsorContainer container;

        public CastleWindsorControllerFactory(IWindsorContainer container)
        {
            this.container = container;
        }

        public override IController CreateController(RequestContext requestContext, string controllerName)
        {
            return container.Resolve(controllerName) as IController;
        }

        public override void ReleaseController(IController controller)
        {
            this.container.Release(controller);
        }
    }

Does anyone know what changes I need to make to make it work with RenderAction?

I also find the error message slightly strange because it talks about multiple requests, but from what I can tell RenderAction doesn't actually create another request (BeginRequest isn't fired again).

© Stack Overflow or respective owner

Related posts about castle-windsor

Related posts about asp.net-mvc-2