Tigraine
Daniel Hoelbling talks about programming

ARFetch attribute in MonoRail

July 20th, 2009 . by Daniel Hölbling

MonoRail and ASP.NET MVC while being very different both almost mirror their features. Few things are impossible in one of both and the only really major difference between those two is that MonoRail comes packed with a suggested data access strategy: ActiveRecord.

This pre-packing is completely optional, it’s very easy to implement whatever data access logic you like, but if you choose ActiveRecord you’ll benefit from some nice things like the ARFetch attribute.

See this action method and judge for yourself:

public void Detail([ARFetch("Id")] NewsPost post)
{
    PropertyBag["post"] = post;
}

You just tell MonoRail through ARFetch what request-parameter is the object’s Id and it will fetch that entity from your DB and pass it into your method. It’s so simple that it’s almost tragic, yet it’s a huge time saver in most CRUD cases (edit, update and delete usually involve fetching the entity first).

Also, for a change, ARFetch is one of those few things inside MonoRail that needs zero documentation. It just works! (Besides the fact that you need to know it exists of course).


  • Fábio Batista

    The [ARFetch] was one of my first contributions to Castle Project ;) I was trying to get away from the heavyweight [ARDataBind] attribute. I’m glad more people liked it.

    Don’t forget the even simpler use:
    public void Detail([ARFetch] NewsPost post) { … }
    This will search for a parameter named “post”.