Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

Source code checked in, #6eb7f13ca6158800a18dcb299dca481277513cbd

$
0
0
Fixes to Attribute routing and add EnsureInitialized(). AttrRouting does 2 things that cause a lot of subtle differences between it and regular routing. - Method constraints. ( 954,1145, 1177) - queries for ActionDescriptors while HttpConfiguration is still being setup (1131, 1165. ) This change fixes those: - Push verb filtering from routing (which used method constraints) into Action selection. - defer all queries until after HttpConfiguration. - add HttpConfiguration.EnsureInitialized() which ensures Initializer is called. This makes the lazy init more deterministic. Today, the initializer runs on the first request. But that's after routing. So you couldn't set routes in the initializer. Specifically, we add a single custom IHttpRoute route that handles all of attribute based routing. The route is added immediately, so it has the correct location in the route table, but it has deferred initialization until after HttpConfiguration.Initialize. (see AttrRoute in HttpConfigurationExtensions) The AttrRoute has a nested route collection that has the same routes we generate before. But the route does not use method constraints. Instead, it has a custom match (and hence a custom IHttpRouteData) that returns the union of possible routes, and then it uses action selection like normal. We add stub routes for generation purposes. GetRouteData always returns null, but they still implement GetVirtualPath(). See HttpConfigurationExtensionsTest.cs, the unit tests are just updated to inspect that nested route collection instead of the main one. But it's still the same routes. And some of the errors are deferred from MapHttpAttributeRoutes() until Initialize(). Once action selection determines which action, it swaps out the composite route data with the specific route data for that action (see ElevateRouteData). This swap is stable so action selection can be called on the new result and get the same results. Before, the Route had the ActionDescriptors. Since AttrRoute is a composite of all possible attribute routes, now the interesting list of ActionDescriptors is on the RouteData

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>