Sunday, January 29, 2012

Single Action Controller - Take 2

After almost a year of using the first version of Single Action Controllers over the ASP.NET MVC (, I have applied a few improvements on it. I particularly didn't like the requirement to inherit from a custom class (SingleActionController), and the boilerplate code required in your Global.asax.

So, the current implementation (also available as a NuGet package at doesn't require your controller class to inherit from SingleActionController but from the usual Controller class, and provides a helper method for Autofac users:


protected void Application_Start()
  var builder = new ContainerBuilder();

  // Register your dependencies

  builder.RegisterTypesForSingleActionControllers(Assembly.GetExecutingAssembly(), "Base namespace of your controllers");

A controller:

using MyCompany.MyProject.ViewModels.Author;

// Name your namespace after your controller.
// This works very nicely with the directory structure you create in your project.
namespace MyCompany.MyProject.Controllers.Author
  // Name your class after your Action and make it inherit from the standard Controller
  public class Index : Controller
    // One single action named Execute
    public ActionResult Execute(FilterDataModel filter) { ... }

Post a Comment