colinramsay.co.uk

New Monorail Routing

17 Oct 2007

Jason alerted me to an SVN commit by Hammett which begins to introduce a new style of routing support into Monorail. The commit message says that he "Added RoutingEngine, initial work to create a cooler routing support inspired on MS MVC", and by looking at the test case for this new engine, it does indeed look cooler.

To add a rule:

routingEngine.Add(PatternRule.Build("ProductByName", "product/<name>", typeof(ProductController), "View"));

</code>

Which will match the URL http://www.domain.com/product/iPod and send it to the view action on the product controller, passing in "iPod" as the name parameter. It's also naming the route as "ProductByName" but I'm not sure of the application of this right now...

The thing I like about this approach is that it's a lot more readable than the current routing engine. It's not going to set the world on fire but this, coupled with RC3's new UrlBuilder, will make for a pain-free means of manipulating your URLs.

Feedback or questions on this post? Create an issue on GitHub.