Extension point in asp.net mvc
-
Extending route.
Route matching is first step mvc framework, we can customize how route is matched by adding constraint, and default, and dataToken. We can implement IRouteConstraint. Here is ASP.NET MVC Tip #30 – Create Custom Route Constraints
-
Extending IRouteHandler
When we register route, by default the route handler is MvcRouteHandler. We can create a class implmenting IRouteHandler, of we can sub class MvcRouteHandler
-
Exending MvcHandler
MvcHandler is IHttpHandler, we can substitute with a MvcHandler sub class, or a complete new IHttpHandler , or override MvcHandler's ProcessRequest method. We can override ProcessRequest(HttpContextBase httpContext) method.
-
Extending ControllerFactory and Controller. We can decide how a controller is created. A dummy example is as follow. But you can create a controller by using IoC container.
ControllerBuilder.Current.SetControllerFactory(new ObjectControllerFactory()); public class ObjectControllerFactory:DefaultControllerFactory { public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName) { if (controllerName.ToLower() == "object") { return new ObjectController(new object()); } else { return base.CreateController(requestContext, controllerName); } } }
-
Extending the ActionResult.
-
Extending the Controller.
Extending ModelBinder
Extending ViewResult
Extending ViewEngine, and IView
We can subclass the default WebFormViewEngine, or implement and IViewEngine. The interesting method is FindView and FindPartialView. </li>
-
Extending ViewPage or ViewUserControl
Extending HtmlHelper by adding HtmlHelper extension method.
</ol>