arrow-left arrow-right brightness-2 chevron-left chevron-right circle-half-full dots-horizontal facebook-box facebook loader magnify menu-down RSS star Twitter twitter GitHub white-balance-sunny window-close
Magellan Route Registration
1 min read

Magellan Route Registration

This is an old post and doesn't necessarily reflect my current thinking on a topic, and some links or images may not work. The text is preserved here for posterity.

This week I have been working on a routing system for Magellan. The goal was to make it very similar to ASP.NET's style of routing:

Routes.Register("Default", 
    "{controller}/{action}/{id}",                            // Path specification
    new { controller = "Home", action = "Index", id = "" },  // Defaults
    new { id = "^[0-9]+$" }                                  // Constraints
);

Unfortunately, I hadn't counted on Silverlight's security implementation. Since anonymous types are internal, I can't use reflection to pull apart the defaults and constraints the way ASP.NET MVC does.

Which of these syntaxes do you prefer?

Routes.Register("Default", "{controller}/{action}/{id}")
    .Defaults(controller => "Home", action => "Index", id => "")
    .Constraints(id => "^[0-9]+$");

Routes.Register("Default", 
    "{controller}/{action}/{id}",
    new Defaults(controller => "Home", action => "Index", id => ""),
    new Constraints(id => "^[0-9]+$")
);

Alternatively, please suggest a better alternative :)

Enjoying these posts? Subscribe for more

Subscribe now
Already have an account? Sign in
Paul Stovell's Blog

Hello, I'm Paul Stovell

I'm a Brisbane-based software developer, and founder of Octopus Deploy, a DevOps automation software company. This is my personal blog where I write about my journey with Octopus and software development.

I write new blog posts about once a month. Subscribe and I'll send you an email when I publish something new.

Subscribe

Comments

You've successfully subscribed to Paul Stovell's Blog.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.