ASP.NET MVC 3: Updating controller factories to RC

With ASP.NET MVC 3 RC there is change in IControllerFactory interface. This interface includes new method called GetControllerSessionBehavior(). This method returns value from SessionStateBehavior enum. ASP.NET MVC uses this method to find out how to handle session for given controller.

If you don’t plan to do any advanced stuff with session state then the easiest way to get your controller factories work again is to add the following method to them.

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

Now your controller factories should compile again.

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

    2 thoughts on “ASP.NET MVC 3: Updating controller factories to RC

    • November 23, 2010 at 9:29 am
      Permalink

      Do you even need to have a controller factory any more? I am using structuremap and only implement the IDependencyResolver interface – MVC 3 uses this internally and the controller resolution is handled automatically.

      Do you have some custom behaviour inside your controller factory that you wouldn’t get if you just implemented the generic dependency resolver?

    Leave a Reply

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