Skip to content

Instantly share code, notes, and snippets.

@jglozano
Created August 18, 2010 13:51
Show Gist options
  • Save jglozano/534787 to your computer and use it in GitHub Desktop.
Save jglozano/534787 to your computer and use it in GitHub Desktop.
using System;
using System.Web.Mvc;
using System.Web.Mvc.Async;
public class SimpleAsyncControllerFactory : TurbineControllerFactory {
public SimpleAsyncControllerFactory(IServiceLocator locator) : base(locator) {
}
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType) {
if (controllerType == null) {
// this will make sure that the MVC framework throws the corresponding
// exception for a non-registered controller
return base.GetControllerInstance(requestContext, controllerType);
}
var instance = ServiceLocator.Resolve<IController>(controllerType);
var controller = instance as Controller;
// If you inherit from controller, implement this fine work around
if (controller != null && !controller.IsType<IAsyncController>()) {
controller.ActionInvoker = GetActionInvoker();
}
return controller;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment