Taking the traditional 3 layer approach (not necessarily 3 tiers):
UI
BLL
DAL
How does NHibernate fit? In most cases I see people allowing NHibernate to directly populate domain objects/entities, which obviously requires a reference from NHibernate to these entities. If domain entities are part of the BLL, this seems to require a reference from the DAL (where NHibernate resides) to the BLL (where domain objects reside).
Doesn’t this go against the typical thinking of separating each layer, with each layer only being dependent on the one below it? What am I missing here?
I can give you an example, how I generally layer with NHibernate for a n-tier architecture:
Data Access Layer
SessionFactoryExample for a mapping:
Business Layer
Example for a repository:
Example for a base repository:
Domain Layer
So, the only layer which is referencing NHibernate is actually the data layer and the business (
NHibernate.ISession). The domain layer is shared between all layers and does not know about NHibernate. For simplicy you could merge the business and data layer into one layer. I generally tend to seperate them, but it depends on the project size.If you really want seperation, I also suggest you to have a look at dependency injection to reduce the dependencies between different layers.
Hope that helps you.