views:

234

answers:

1

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: http://stackoverflow.com/questions/1207833/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

+2  A: 

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.

Michael Shimmins
+1 for the DI usage. Each app may just need a "context" built in with such info. The context is different for each style of app, e.g. a web focused one and a desktop focused context. In the case above the infrastructure code (e.g. the repository) just gets a context or the respective `ISession` instance, how its made is different for each type of app.
Paul Kohler
thanks guys, do you know of any examples of this approach i can check out?
alex
I *think* Sh#rp Architecture does it http://www.sharparchitecture.net/ but I haven't looked at it too extensively, and not for a while, so take it with a grain of salt.
Michael Shimmins