I have an application built using Fluent NHibernate and ASP.NET MVC. It is divided into 5 projects, at the moment.
WEB
The ASP.NET MVC project contains only the HTML, CSS, Controllers, and very project specific Validators and Model Binders, as well as the IoC container Ninject
MODELS
The Models project contains the domain objects, IRepository<T>
, Services that use the Repository, and ancillary code not related to database operations.
PERSISTENCE
The Persistence project contains Fluent nHibernate Mapping, ISessionFactory
mapping, Repository<T> : IRepository<T>
implementation, etc.
PERSISTENCE.UTILITIES
This is an ancillary project that has little to do with my actual final product. This is where I am putting things like test database seeding, default collections for quick-setup, etc.
TEST
Unit Testing Project
The problem I am running into is between Models
an Persistence
. There are certain times when I need to use eager loading. In nHibernate, I would use Query<T>().Fetch(...)
to do this. This would work fine, except Models.dll
has no concept of nHibernate. It has no concept of any library except System.dll
and is completely standalone.
Is there a specific way I can add the ability to do Eager loading into my IRepository
without knowledge of NHibernate.Linq
? I cannot add a method that takes any kind of lambda expression that would include Fetch
in it because my persistence layer doesn't exist in the Model layer. But the IRepository<T>
exists in the model layer, because it is used in the Service objects, which also have no concept of the database. They simply access the appropriate repositories. The Repositories are not exposed to the Web
Layer, just the appropriate Services.
Any ideas?
Persistence
project... Why does youModels
project need to know about it? – Charlinohow
to keep it in persistence project. I can't pass a query that has knowledge of the NHibernateFetch
method through myIRepository
- but theIRepository
has to be in theModels
project. – Ciel