Background
I read all blogs and nhibernate session management documentation. My problem, I need it for winforms and webforms. That's right, I use the same data layer in winforms (windows.exe) and webforms (asp.net) applications. I read a little about the level of work and is a good choice for winforms. Storing an nhibernate session in HttpRequest.Current.Items seems like a good way for web applications. But what about combo deals? I have web apps, windows apps, and WCF services that should all use the same nhibernate data layer. So back to my question ...
I plan to use this design: NhibernateBestPractices in my web application, for example:
private ISession ThreadSession {
get {
if (IsInWebContext()) {
return (ISession)HttpContext.Current.Items[SESSION_KEY];
}
else {
return (ISession)CallContext.GetData(SESSION_KEY);
}
}
set {
if (IsInWebContext()) {
HttpContext.Current.Items[SESSION_KEY] = value;
}
else {
CallContext.SetData(SESSION_KEY, value);
}
}
}
Problem
The problem that I am encountering when using this code in my Windows application is with the line
CallContext.SetData(SESSION_KEY, value);
If I understand CallContext () correctly, this will allow the session to open the entire lifespan of my Windows application, since it stores the nhibernate session as part of the main application stream. And I heard all kinds of bad things about keeping the nhibernate session open for too long, and I know by design that doesn't mean staying open for too long. If all my assumptions are correct, then the above line of code is no, no.
, , nhibernate Windows. - HttpRequest. Windows, nhibernate ( ) . , .
, nhibernate Windows, ( , - ) ( , )?
** **
,
http://msdn.microsoft.com/en-us/magazine/dd882510.aspx
http://www.codeinsanity.com/2008/09/unit-of-work-pattern.html