I'm very pleased to announce the release of NHibernate Best Practices with ASP.NET, 1.2nd Ed. on CodeProject.com.
Preface to the 1.2nd Edition
In March of 2006 I published my initial thoughts on NHibernate best practices with ASP.NET, generics and unit tests. I've been delighted to learn that these ideas have been implemented in a number of real-world scenarios with strong success. Since then, I've worked with many people to refine these ideas, learn from mistakes and leverage a more powerful version of NHibernate. Accordingly, although only a modest, yet important, amount of modification has been made to the underlying architecture, some other important factors have been updated and addressed in this article:
- Quite simply, NHibernate is awesome. In the previous edition of this article, I assumed you already knew this...but I now try to convince the dissenters as well.
- NHibernate 1.2 natively supports generics.
- NHibernate 1.2 natively supports nullable types.
- NHibernate 1.2 natively supports mapping attributes.
- NHibernate 1.2 can communicate with stored procedures.
- Using CallContext for ISession storage in ASP.NET was susceptible to failure under load.
- Exposing a publicly settable ID property created a point-of-susceptibility.
- Providing automatic parent/child wiring, via Ayende's very helpful NHibernate.Generics, was more headache than help.
- Have you used Rhino Mocks 3.0, NUnitAsp, or Fit? Well, these are all discussed with an expanded emphasis on test-driven development.
- As an alternative to my recommendations, also consider Castle Project's offerings such as MonoRail and/or ActiveRecord for a simple yet powerful out-of-the-box framework for ASP.NET. In fact, if it's technically feasible and you can generate buy-in on your team for these off-the-shelf tools, I would recommend using them over a ground-up solution. But even if you do use Castle Project facilities, this article should still have a lot of useful information for you!
- In addition to those listed above, there are other important refactorings and fixes throughout the article and the code. This edition is by no means just a light touch-up of the original article.
- In addition to an overhaul of the original sample code, an expanded "enterprise" sample has been included demonstrating:
- NHibernate with web services
- NHibernate with multiple databases
- Integration with Castle Windsor
- A reusable data layer for the data access components.
- A simple example of Model-View-Presenter
I hope this article will be chock full of (at least a couple) good ideas no matter what your level of experience is. I look forward to hearing your experiences with the article and any feedback you may have. I've also included some areas for further research for anyone interested in taking the sample framework further.
04-03-2007 3:36 PM