I recently posted a question which was answered by Bryan Watts, regarding generic repository for开发者_如何学C nHibernate.
I'm trying to design my data access to allow various facets - from ASP.net, WCF and Windows Forms / Windows services. I'm a bit confused re: session management etc..
How would I handle this?
I've been checking out code such as: http://membranecms.googlecode.com/svn/
and questions such as: NHibernate Linq Session Management
But what do i do if i don't just do things in a web based environment..?
Do i need to create different repositories for each client? Or do i pass in the ISession into the (for example) UserRepository constructor..?
... as a side note I'm using nHibernate.Linq Also using fluent nHibernate to config my mapping
We use constructor dependency injection in our generic base class Repository<....>. The Repository constructor expects an instance of ISession which is supplied from the IoC container.
The IoC container is initialized at startup depending on which UI is in use.
Definitely no need for different repositories per UI front end.
精彩评论