ASP.NET MVC: Fix IControllerFactory implementation after upgrading from MVC 2 to MVC 3


Recently, I upgraded an ASP.NET MVC 2 application to ASP.NET MVC 3. I used the ASP.NET MVC 3 Application Upgrader tool (see this blog post for more information) which enables you to upgrade an existing MVC 2 project automatically.

After the upgrade process I got an compile error in my custom controller factory, because the method IControllerFactory.GetControllerSessionBehavior that was added in MVC 3 was not implemented. The simple trick here is to add the missing method with the following (default) implementation:

public class MyControllerFactory : IControllerFactory
{
  public IController CreateController(RequestContext context, string controllerName)
  {
    [...] 
  }

  public void ReleaseController(IController controller)
  {
    [...]
  }

  public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
  {
    return SessionStateBehavior.Default;
  }
}
,

One response to “ASP.NET MVC: Fix IControllerFactory implementation after upgrading from MVC 2 to MVC 3”

Leave a Reply

Your email address will not be published. Required fields are marked *