I've hit a wall with trying to decouple NHibernate from my services layer. My architecture looks like this:
web -> services -> repositories -> nhibernate -> db
I want to be able to spawn nhibernate queries from my services layer and possibly my web layer without those layers knowing what orm they are dealing with. Currently, I have a find method on all of my repositories that takes in IList<object[]> criteria
. This allows me to pass in a list of criteria such as new object() {"Username", usernameVariable};
from anywhere in my architecture. NHibernate takes this in and creates a new Criteria object and adds in the passed in criteria. This works fine for basic searches from my service layer, but I would like to have the ability to pass in a query object that my repository translates into an NHibernate Criteria.
Really, I would love to implement something like what is described in this question: Is there value in abstracting nhibernate criterion. I'm just not finding any good resources on how to implement something like this. Is the method described in that question a good approach? If so, could anyone provide some pointers on how to implement such a solution?
abstracting away the ORM will:
and all for very little value: the vague option to exchange the ORM framework which will most probably have a lot of other problems
Update: experience
I was once involved in implementing a new provider of an existing DAL abstraction. It ended up performing badly, introduced a lot of bugs, Errorhandling was a mess and sometimes used stale data because the application assumed the default implementation. Reasons:
It took a lot of refactoring of the application:
Additional points:
Porting (of business tasks) would have been a lot less painfull IMO as we did that for a few because of performance.
Update2: experience2: RoadBlocks while trying to port from NHibernate to EntityFramework (impl with NH but couldn't with EF 4 in reasonable time)