End Loose Ends

NHibernate

How To Avoid Accessing Repositories from Domain Objects

I was reading the comments on Udi Dahan’s blog post about Domain Driven Design when I ran into a frequently asked question regarding domain classes and repository access.  Usually, the questions are similar to the following: While invoking behaviour on one aggregate root, how do I load another aggregate from a repository? How do I inject a repository instance into a domain object?    I generally prefer to tackle this problem using an approach that keeps the domain model free of storage concerns. The Obligatory Customer/Order...

Use NHibernate Transactions

Ayende recently mentioned the importance of using transactions with NHibernate: “NHibernate assume that all access to the database is done under a transaction, and strongly discourage any use of the session without a transaction.” In some ways, I wish it wasn’t possible to use sessions without transactions as it seems to cause unpredictable results.  Take, for example, the following code from a unit test (for simplicity, the code has been slightly modified to only refer to NHibernate interfaces): using (var session = SessionFactory.OpenSession()) { var item = RunningTask.Start (); ...