FubuMVC – No Strings Attached II

In my last post I was talking about how stringless fubuMVC is and how it simplifies our work.

One of the points I was still struggling with was how to add a convention to add a certain route pattern; in other words, I was trying to figure out what was the Fubu equivalent to ASP.NET MVC’s

routes.MapRoute(
 "Default", // Route name
 "{controller}/{action}/{id}", // URL with parameters
 new {controller = "Home", action = "Index", id = ""} // Parameter defaults
);

Well, it seems that this is way more simple than I thought.

The first thing you have to do is write an interface for all your models with an Id property, something along the lines of:

public interface IIdentifiable
 {
 int Id { get; set; }
 }

Now, for each and every InputModel you wish to have the Id in the url as shown above (controller/action/Id), you’ll need to implement your IIdentifiable and then in your FubuRegistry class, you add the following:

Routes.
IgnoreControllerNamespaceEntirely().
ForInputTypesOf<IIdentifiable>(x => x.RouteInputFor(model => model.Id));

And that’s it!! Magic, isn’t it?

What I personally love about it is the fact that a) no strings, yet again, but more importantly- b) you don’t have to struggle with the much less intuitive api of ASP.NET MVC that forces you to write the more specific routes before the more general ones. Fubu api is by far more user friendly!

Advertisements
Explore posts in the same categories: Fubu

Tags:

You can comment below, or link to this permanent URL from your own site.

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


%d bloggers like this: