Thinking in Asp Net MVC – (Http Request Route parsing)

Thinking in Asp Net MVC – (Http Request Route parsing)

Route related models

RouteBase{
abstract RouteData GetRouteData(HttpContextBase httpContext);
abstract VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
}

Route : RouteBase{
...
}
RouteCollection: Collection{
...
}
RouteTable{
static RouteCollection Routes {get;}
}
RouteData{
RouteData();
RouteData(RouteBase route, IRouteHanlder routeHandler);
string GetRequiredString(string valueName);

RouteBase Route {get;set;}
IRouteHandler RouteHandler {get;set;}
RouteValueDictionary DataTokens {get;}
RouteValueDictionary Values {get;}
}
RouteDataDictionary : IDictionary<string,object>,
ICollection<KeyValuePair<string,object>>,
IEnumerable<KeyValuePair<string, object>>,
IEnumerable{

}
IRouteHandler{
IHttpHandler GetHttpHandler(RequestContext requestContext);
}
VirtualPathData{
VirtualPathData(RouteBase route, string virtualPath)

RouteValueDictionary DataTokens {get;}
RouteBase Route {get;set;}
string VirtualPath {get;set;}
}
RequestContext{
RequestContext();
RequestContext(HttpContextBase httpContext, RouteData routeData);

virtual HttpContextBase HttpContext {get;set;}
virtual RouteData RouteData {get;set;}
}

IRouteConstraint {
bool Match(...)
}
HttpMethodConstraint : IRouteConstraint{
...
}

What we can learn from Design

  • use abstraction achieve flexibility. Behaviors those need to be more flexible has been pulled up (abstract, virtual).
  • talk to abstraction .RouteBase only talk to IRouteHandler, lease knowledge.
  • static when nessacery .all requests should share the same Route Infomation.
  • Use ‘Dictionary’ achieve extensicibility . give ourside a chance to attach its own business data into ‘Route world’

MVC Routing flow

Http Request :
HTTPApplication_PostResolveRequestCache event:
UrlRouteModule (HTTP Module):
RegisterRoutes
MapPageRoute
RegisterAreaRoutes
MapAreaRoute:
Try find in Cache
Map area route
Parse out Handler from route:
PageRouteHandler (Create From Virtual Path)
MvcRouteHandler (MVC Handler):
...

Author: lanliang

Programmer.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s