简体   繁体   中英

nHibernate session - Using repository pattern in Web, windows, wcf etc

I recently posted a question which was answered by Bryan Watts, regarding generic repository for 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM