Tuesday, September 15, 2009

When Easier is Better

Most of the people I currently or have worked with know that I have a strong preference for NHibernate for my persistence mechanism. I typically use a repository pattern, often with services hiding the repositories from the outside world. This is great as I get enterprise scalable domain-driven solutions up and running pretty quick and helps me focus on fixing business problem, not spinning my wheels with infrastructure details. However some time having DTO's, services, repositories, mapping files, anti-corruption/translation layers etc are just overkill. This is where is would typically say "Use Linq2Sql", if someone asked me what they should use, but its probably not what I would use. I like the idea of having the flexibility of moving from a simple domain to a complex domain with out too much problem. Enter Castle Active Record

Active record is in no way a new concept (PEAA p160) but is heavily under used in the .Net realm. AR is a great pattern when you are fleshing out a domain. You can very quickly start building up relationships have screens up and running for client very quickly. This is great for spikes but also for writing real code. The database can be generated from the code (Castle AR sits on top of NHibernate) so it is a great fix for fast moving agile project, especially in the initial sprints. The thing I like most about it is that if I decide I want a more complex domain, all is not lost; I remove the Castle attributes and references wrap a repository pattern around it and I am done. It really is that easy. All my existing domain unit tests should still pass. In a matter of hours you could switch from a developed 2 tier app to an enterprise ready scalable architecture.

Basically AR is great if you are lazy (or need results now).

To prove all of this I plan on presenting Castle AR in an up coming Perth Alt.Net meeting. Originally I had wanted to show NHibernate however I think the progression from AR to NH will help show both of there benefits. This may also allow us to show the limits of both... time will tell.

As a side note the castle stack (as well as NHibernate) has had a "proper" release this year so if you haven't had a look in a while check it out : http://www.castleproject.org/castle/download.html

Links - Articles


All you wanted to know about Castle ActiveRecord - Part I

All you wanted to know about Castle ActiveRecord - Part II

Links - Videos

Ayende Rahien - Using Active Record to write less code (Oredev 2008) << Watch me I'm great!

Ayende & Hammet - Painless Persistence with Castle ActiveRecord (JAOO)

No comments: