I’d like to use a class extending Controller as the default base type for controllers in my project, as opposed to using Controller itself. So, I would be doing this:
public class FooController : MyBaseController
Is there a way I can enforce this, so that people cannot create controllers which extend Controller directly?
However I prefer the unit testing approach above here is another one by using a custom controller factory.
You can set it up in the application start method of your Global.asax like this:
This of course causes a runtime exception when not deriving from
MyBaseControllerwhich may not be suitable in your current scenario.