tags:

views:

58

answers:

2

I have a c# solution with 3 projects - Data, WCF and UI. The first one is a class library that talks to db. It's exposed via the second one, which is of type WCF Service Library - the reason for that is it will be exposed in third project - Asp.net app called UI - as a simple svc pointing to dll.

Just to point it out, I'm not using Repository pattern.

I need to have ISession for a WCF call (similiar to Session-per-request approach for asp.net). Can anyone share a solution that simply works? I don't want to use any IOC for that.

A: 

Each call to service is associated with unique OperationContext. OperationContext doesn't have any store for custom objects but you can implement extension. By setting session in MessageInspector you can initiate NHibernate Session per call in centralized place and access your extended context in any operation.

Ladislav Mrnka
This is quite WCF-related. What about using this ISession in Data project? I would like to keep it without any WCF context related knowledge.
StupidDeveloper
A: 

Use WcfOperationSessionContext (new in 3.0).

Once bound, your Data classes just have to use SessionFactory.GetCurrentSession().

Diego Mijelshon
Will use it for sure. Just when nh will not be alpha anymore!
StupidDeveloper
If that's an issue, you can just copy the class from here: https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate/src/NHibernate/Context/WcfOperationSessionContext.cs and use it in your configuration.
Diego Mijelshon