Nov 17, 2011 at 8:15 AM
Edited Nov 17, 2011 at 8:58 AM
A little follow up question on this one
So I got my modules set up (Unity) and a data module that will do my persistence. That is done with nHibernate. Using nHibernate I have a IRepository<T> and a Repository<T> that will do my most basic CRUD operations and also from which
specialized repositories can inherit in different modules.
Ideally I'd like my data module to be independent on the ORM (say in 5 years everyone is all excited about some new technology/ORM). I find this hard as a repository takes in an ISession (nHibernate interface) to work on.
What I'd like to do is (and very open to other suggestions)
|- IRepository<T> where T : IEntity
|- Customer : IEntity
|- Repository<T>(ISession session) (register as a service in module Initialize)
|- SessionFactory (as a service) (singleton with OpenSession() method)
|- CustomerRepository<Customer>(ISession session) : Repository<T>(session)
Reading this article of best practices using nHibernate with Windows application it encourages to have a session-per-form scenario. Then I have a dependecy on my session object type
(ISession) throughout my application. Unplugging my data module and inserting a new one will not work as I will have to sort out all the places ISession were used.
Also I found registering generic services (Repository<T>) hard as I would like my module to define that T. A way around is to move the <T> to the method implementations instead (GetById<T> where T : IEntity)
But my biggest problem is that how to inherit from my base repository from my modules. Does it makes sense to move it to Infrastructure? Then only my SessionFactory will be left in my Data module with some conventions.
So to sum it up - I (think I) understand the concept of sharing services and so on in Prism, but how to do it in a generic way and without getting a dependency on my ORM implementation? Adding a business layer module that will hold all the session
implementation? As such I will only have to change two modules in the future.
Any thoughts on this is appreciated :)