Just to expand Craig Stutz's answer :
ControllerFactory processes when the controller is installed. When implementing the IControllerFactory interface, one of the methods that must be implemented is ReleaseController.
I'm not sure if you use ControllerFactory, regardless of whether you roll your own, but in Reflector looking at DefaultControllerFactory, the ReleaseController method is implemented as follows:
public virtual void ReleaseController(IController controller) { IDisposable disposable = controller as IDisposable; if (disposable != null) { disposable.Dispose(); } }
The reference to the IController is passed, if this controller implements IDisposable, then this Dispose method is called. Thus, if you have something that you need to delete after completing the request, that is, after rendering the view. Inherit IDisposable and put your logic in the Dispose method to free up any resources.
The ReleaseController method is called by System.Web.Mvc.MvcHandler, which processes the request and implements IHttpHandler. ProcessRequest passes the HttpContext specified to it and starts the controller search process to process the request by calling into the implemented ControllerFactory. If you look in the ProcessRequest method, you will see a finally block that calls the ControllerFactory ReleaseController. This is only called when the controller returns a ViewResult.
Dale Ragan Sep 04 '09 at 16:06 2009-09-04 16:06
source share