Factory Windsor Controller and RenderAction Lock

I encountered a problem while using my Castle Windsor Factory controller with the new RenderAction method. The following error message appears:

A single instance of MyController cannot be used to process multiple requests. If you are using a custom Factory controller, make sure it creates a new controller instance for each request.

This is the code of my factory controller:

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 found that the error message is a little strange because it speaks of several requests, but from what I can tell, RenderAction does not actually create another request (BeginRequest does not start again).

+4
source share
1 answer

I believe the default setting for Castle Windsor is Singleton. You must change this to Transient in your Web.Config or by placing this attribute in your [Transient] class.

+10
source

Source: https://habr.com/ru/post/1309059/


All Articles