Contributors:

Nick Harrison
Chris Massey

Overview of Controller Extensibility

An Introduction to MVC Extensibility [Simple-Talk]

Published in 2011. Because ASP.NET MVC has been designed with extensibility as its design principle; almost every logical step of the processing pipeline can be replaced with your own implementation. Simone Chiaretta has started a series that explains how to implement extensions to ASP.NET MVC, stepping progressively through the entire request pipeline, and starts with an overview of what is possible.

Working with Controller Factories

Inside the MVC Controller Factory [DotNetSlackers]

Published in 2010. Dino Esposito gives an introduction to the controller factory and how to work with it. Dino covers the steps of grabbing the controller name, the controller type and instance, and releasing the controller instance once you’re done with it. This is an excellent, tightly-bounded how-to, with very readable code.

Keyvan Nayyeri – Custom Controller Factory in MVC [Blog]

Published in 2008. Keyvan Nayyeri has published a series  covering the 13 major extensibility points in ASP.NET MVC, and creating a custom controller factory is the third in his series. There’s a brisk introduction to the theory, followed by well-documented code samples.

Sankarsan Bose – Developing Custom ControllerFactory [Blog]

Published in 2008. Sankarsan Bose provides a very concise how-to for developing a custom controller factory. There is very little discussion around the process, and he pretty much just steps straight into code, so this is probably only worth reading once you’re comfortable with the idea of custom controller factories and why you might need to implement one.

Cengiz Han – Custom Controller Factory in MVC [Blog]

Published in 2010. Cengiz Han describes not only what the controller factory is, but also why you might need to use a custom controller factory and how to implement one. Although the article is always the easiest to read, he has provided plenty of clear code and screenshots to explain the process.

Controller Lookup and Default Controller Factory [The Code Project]

Published in 2012. Vijaya Anand has written a thorough article explaining what controller factories are, and how the DefaultControllerFactory is put together. The article is detailed enough to step into what caching strategies the factory uses, and to cover supporting classes. This is detailed post which is an excellent place to start if you want to get a solid understanding of controller factories in general.

Action Invokers

John Zablocki – Dynamic Actions in MVC [Blog]

Published in 2010. John Zablocki starts with a description of situations in which MVCs normal design conventions can result in lots of redundant methods and un-reusable code, and then goes on to discuss how avoid this with Dynamic Actions. John steps through the process of building this kind of functionality, illustrating how the controller factory and action invoker come into play throughout.

Dynamic Action Filters in MVC [MSDN Magazine]

Published in 2010. Dino Esposito discusses Dynamic Action Filters, and gives a solid introduction to action invokers and the role they play in the execution of action methods. The article walks through the process of performing an action, covering each step taken by the framework along the way. Over the course of the article, Dino covers how to create a custom Action Invoker, as well as the complete Action Lifecycle.

Arun Mahendrakar – MVC ‘Extendable Hooks’: ControllerActionInvoker Class [Blog]

Published in 2011. Arun Mahendrakar focuses completely on the ControllerActionInvoker class as an extensibility hook. The post takes a look at the MVC source code to explain the class works, and finishes with a small demonstration of how you can control output formats.

Custom Action Method Selector

Custom Action Method Selector in MVC [The Code Project]

Published in 2011. Jigar Bagadai starts with the idea that routing is complex when dealing with methods sharing a name, or actions following form data submissions. The rest of the article is very short, and steps through ActionMethodSelector attributes, and how to build your own.

Robert Koritnik – Custom Action Method Selector Attributes in MVC [Blog]

Published in 2010. Robert Koritnik gives some good real-world examples of when you might want to build your own custom action method selectors, and explains what action method selectors actually are. Rather than walking through how to create your own custom Selectors, Robert showcases the ones that he’s build (and explains why they’re structured as they are), and finishes with some information when and how you should set action method selector attributes.

Handling Unknown Actions

Handing Unknown Actions in MVC [The Code Project]

Published in 2008. Farooq Kaiser provides a very concise description of the Controller.HandleUnknownAction method, covering its purpose and implementation. There’s very little detail in terms of how to extend functionality, so read this if you want a basic overview, or just the simplest handling of unknown actions.

HandleUnknownAction in MVC – Be Careful [CodeBetter]

Published in 2008. David Hayden points out that, wonderful though HandleUnknownAction is, it fails to take attributes (like ActionMethodSelectorAttribute) into consideration. A very simple cautionary point, with a short demonstration of the point.

How to have generic actions in MVC, but handle unknown actions [StackOverflow]

Published in 2010. The OP is trying to use a generic routing solution, but still be able to catch any unknown actions without requiring hard-coding of all his sub-pages. The accepted solution suggests using a constraint with a single route, and provides the necessary code to demonstrate.

Overriding HTTP Methods

Is it possible to implement X-HTTP-Method-Override in MVC? [StackOverflow]

Published in 2008. The OP is trying to implement a RESTful API using MVC, but is having trouble getting callers to use the X-HTTP-Method-Override header to override the HTTP method. The accepted solution suggestion turning the AcceptsVerbsAttribute into a subclass and overriding the IsValidForRequest() method.

Dylan Beattie – RESTful in MVC 2 Preview 2 [Blog]

Published in 2008. Dylan Beattie walks through the process of setting up RESTful routing in MVC 2 Preview 2, covering the usefulness of the Html.HttpMethodOverride helper method, as well as the little gotchas to look out for along the way. It’s a relatively theoretical exercise, as he closes by explaining that he’d side-step the whole problem by trusting in the routing engine and route constraints.

Using Sessionless controllers

Nadeem Afana – Sessionless Controllers and TempData in MVC [Blog]

Published in 2010. Nadeem Afana gives a brief introduction to sessionless controllers, covering when you might want to employ them, and a little background into how they’re configured, before diving into the code.

Code Inside – HowTo: Sessionless Controller in MVC3 – What and Why [Blog]

Published in 2011. Although slightly awkwardly written, and occasionally hard to decipher, this post not only covers why and when you should use sessionless controllers (one case is for parallel processing of multiple AJAX callbacks), but also considerations you should bear in mind and performance data comparing both session and sessionless options..

Sessionless Controllers in MVC 3 [DotNetCurry]

Published in 2010. Malcolm Sheridan walks through the bare mechanics of how to create sessionless controllers, right down to where to click inside Visual Studio. This is a very narrow post, with minimal discussion around the topic – it just covers the set up and parameters of sessionless controllers.

Using Asynchronous controllers

Imran Baloch – AsyncCotnrollers vs SessionLess Controller [Blog]

Published in 2011. Imran Baloch provides a highly detailed comparison of async and sessionless controllers, providing a demo application to demonstrate his points, and very detailed explanations to accompany his code samples. In closing, Imran advocates both approaches for appropriate situations.

Using an Asynchronous Controller in MVC [MSDN Library]

Unknown publishing date, but targeting MVC 3. Standard MSDN documentation describing the AsyncController class with an accompanying Visual Studio project and source code. The article describes how requests are process, when to use either synchronous or asynchronous action methods, and even how to convert one to the other. This is a thorough piece of reference material, and is an excellent place to explore async controllers.

The Evolution of Asynchronous Controllers in MVC [Blog]

Published in 2012. Simone Chiaretta gives a bit of a history lesson, illustrating how the implementation of asynchronous controllers has evolved from MVC 2 / 3 all the way to MVC 4 (and C#5). It’s a remarkably concise post, and really just focuses on how to implement the controllers, rather than when it is advisable or how to actually make the best use of them. Interesting, and worth a look if you’re working with legacy code.

Working with Asynchronous Operations in MVC [CodeGuru]

Published in 2012. Bipin Joshi provides a comprehensive guide to getting started with asynchronous controllers. The article starts with an introduction to asynchronous operations, and then jumps right into creating and consuming asynchronous controllers, touching upon sessionless controllers. The whole piece is solidly written, and the code samples and clearly formatted.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>