Incorporate AttributeRouting into the web stack

Topics: ASP.NET MVC, ASP.NET Web API
Jul 31, 2012 at 12:54 AM

Hi,

I'm the author of AttributeRouting, an open-source project that allows specifying routes directly on action methods. It is very stable with regards to MVC, but is awaiting the publication of this fix in order to support Web API.

I ask because I was just watching a video where the presenter suggested the author of a web api attribute library submit a pull request, and many folks have mentioned to me they'd like to see this routing strategy baked into the framework. Not that this makes it a good idea, but still....

Because AR isn't a simple change to the framework, I just wanted to gauge interest first. If there is any, then I'd need some guidance regarding the strategy for preparing a pull request. If there's no interest, no problem. Just thought I'd explore this option.

Cheers,

Tim

Jul 31, 2012 at 3:59 AM

Tim, thanks for the suggestion! There definitely is interest -- it is certainly something I have high on the list for further investigation. Filip published a very interesting blog a little while back on the subject. Your thoughts on that approach?

Henrik

[1] http://www.strathweb.com/2012/05/attribute-based-routing-in-asp-net-web-api/

Jul 31, 2012 at 4:08 AM
Edited Jul 31, 2012 at 5:29 AM

Hi Henrik,

My thoughts on that blog post? Not sure what you mean, as he is simply surveying the project. So I would say I tend to agree with all the things he said :). As you contributed the Web API patch to IActionHttpMethodProvider, just want to note that once that patch is public, then AR can fully support both MVC and Web API.

In any case, I would be more than happy to work with you guys on determining a plan to go forward with bringing AttributeRouting into the core framework. Whenever you'd like to discuss in more detail, we can go offline to whatever degree necessary (or stay public in this discussion). From my perspective, the first thing I do in MVC  projects these days is gut the standard global.asax routing and bring in AttributeRouting, so I'd love to see it baked in.

Thanks for the speedy reply.

Tim

Aug 2, 2012 at 6:04 AM

I would love to see AttributeRouting into the WebStack.

It's such a great job that mccalltd have done!

For me it's a 1000 times more intuitiv than the default route config and more flexible!

 

My Vote for that!

 

Best regards

Aug 6, 2012 at 8:32 PM

I agree NoiZy!

I think that is a great job!

 

Greetings!

 

---------------------

paleo brekfast recipes

how to win her back

Sep 21, 2012 at 11:25 PM

Don't adopt AttributeRouting, you can do better than that. Check out MvcCodeRouting.

Sep 26, 2012 at 1:53 AM

The pure fact you are on this page about AttributeRouting (not your project) putting down someone else's project and touting your own is reason enough to ignore it.

How about a post saying 'maybe several options can be worked into the framework' would have been far better.

Sep 26, 2012 at 4:29 AM

If you think it's reason to ignore it, then ignore it. I couldn't care less.

Back to the point, I don't think neither projects should be incorporated ínto the framework. If the ASP.NET team wants to provide a better routing solution, it should be a really good solution, better than AttributeRouting.

Sep 26, 2012 at 4:59 AM

The point is don't come to a public discussion started by the author of that tool and piggy back yours on while saying not to include his.

It's disrespectful.

 

" If the ASP.NET team wants to provide a better routing solution, it should be a really good solution, better than AttributeRouting."

 You mean like your project? The advantage with open source is the commit can go in, and be worked on quite a bit before the next release. IE 'Any project' can be used as a base. Yours, AttributeRouting, the stack overflow source etc. Three 'strong' routing projects that can surely have a good basis.

So let's try a helpful conversation:

Whats wrong with attribute routing? Aspects to get to where we want make sense to be applied to a method.
The constraint syntax is awesome.  Your CustomRoute class seems to serve a similar purpose, so whats the main difference?

Whats a weakness of it? Whats a strength of yours? Whats a weakness of yours?

In yours I see a convention created in a place where ordering of routes is very important. A developer relies on black box route creation behavior to hope the order of routes is correct I didn't see on your main wiki page if you can specify the order, so we 'hope' the routes are created in the proper order. The same goes for AttributeRouting but we can specify an order.

In your project what about optional parameter and route constraints? All of the information surely isn't available in code to make a proper route constraint by convention. You can 'half guess it' and it may work a good portion of the time, but how do you know the business rules for say a FirstName or a default value for Page? So then you are back to using a [CustomRoute()], no?

 

Sep 26, 2012 at 3:36 PM

MvcCodeRouting does not create a convention, people use the {controller}/{action} or {controller}/{action}/{id} all the time, it just recognizes that fact. So, the fundamental question is: do we start with custom routes and add conventional routes when needed, or, do we start with conventional routes and add custom routes when needed.

Routes ordering is always important, specially to avoid URL generation issues. MvcCodeRouting knows how to order routes, no need for hope.

In MvcCodeRouting, optional route parameters are just optional parameters in C# or VB, or you can use the DefaultValue attribute in languages that do not support optional parameters. You can specify a custom constraint using the FromRoute attribute, like this:

public ActionResult Foo([FromRoute(Constraint = @"\d")]int bar);

I think AttributeRouting is successful at what it was designed to do, but all it does is move route management from Global.asax to the controllers.