However, I prefer the unit testing approach above , here is another option using a custom factory controller.
public class MyControllerFactory<T> : DefaultControllerFactory where T : Controller
{
#region Overrides of DefaultControllerFactory
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (!typeof(T).IsAssignableFrom(controllerType))
{
throw new NotSupportedException();
}
return base.GetControllerInstance(requestContext, controllerType);
}
#endregion
}
Global.asax :
ControllerBuilder.Current.SetControllerFactory(new MyControllerFactory<MyBaseController>());
, , , MyBaseController, .