NHibernate Back on My Radar

A little more than a year ago, I did my first sample project with NHibernate during some extended down time at Immedient.

At the time, the project was still in the .x releases (I believe I started with .8).  The one thing that really turned me off was the lack of good samples and starting points to learn from (although I did eventually dig up enough info to get my sample project up and running) and, in particular, the lack of strongly typed lists and collections. 

This is a legacy of the Java implementation of Hibernate, which was addressed some time last year with the release of .Net 2.0 and Generics, actually, but I never got a chance to look into it more as the end of the year was a busy quarter for me.

Over the last few days, I’ve been doing a little bit of studying regarding DLINQ for object persistence (incidentally, I also learned how to do duplex printing with my printer, which was far too confusing).  I recall being quite excited about ObjectSpaces when I was working at Factiva, but I was never able to get my hands on the preview bits.  From what I understand, it was actually very similar to NHibernate in that it required the use of intermediate XML mapping files (although DLINQ also needs those, but only for generating class files since it relies on the use of attributes).

DLINQ is the heir apparent to ObjectSpaces and is superior in every way…it’s just that it’s still in very early alpha stages and won’t be ready for primetime until the release of C# 3.0.  While I love the technology, I’m just not ready to put time into something that’s so open to change at the moment.

So, while I would love to implement DLINQ, it just seemed safer to take a second look at NHibernate, at least for the time being.  The last time that I took a look at it was probably around summer of last year, when I implemented a “toy” site for my sister using Cuyahoga CMS (which uses NHibernate).

With that in mind, I came across a very good CodeProject article on best practices for using NHibernate in a web environment.  As soon as I saw the bit about Generics, my interest was piqued again.  I downloaded the source and followed along and, to my surprise, it seems that my earlier frustration with good examples and usage has slowly been counterbalanced by increased usage of NHibernate.

As a bonus, I came across a great set of links and finally took some time to read about Martin Fowler’s article on Inversion of Control.  This lead me to two frameworks for implementing IoC in .Net: Spring.Net and Castle/Windsor.  To be honest, I didn’t quite “get” IoC and Castle the first time I looked at it (again, when I first started playing with NHibernate).  But I think I’m finally starting to understand it (I won’t say I do fully until I use the framework and really “get” it).  I implemented something similar in a small project that I worked on last year at INS/Immedient (probably would have been much easier to use this instead).

The thing is, I’ve begun to become more and more obsessed with building loosely coupled systems.  So this is just the fix that my brain needed to start thinking about better designs.  Both Spring and Castle seek to address the same issue by utilizing IoC to remove dependencies (see here and here for a comparison of the two, although note that these were written over a year ago and were written by the project leader of Castle).

BONUS: I also came across a blog posting on how to simulate an HttpContext for testing written by the guy that’s leading the Subtext project.  This is actually something I had been curious about (but too lazy to do anything about :-D) for quite a while.

You may also like...