It seems like this would be ideal since lazy-loading requires the original session (I believe).
I also already have a custom Page class that derives from System.Web.UI.Page.
So I'm thinking that a Property like this:
Code:
ISession _dataSession;
ISession DataSession {
get {
if(this._dataSession == null || !this._dataSession.IsOpen) {
if(this._dataSession != null) {
this._dataSession.Close();
}
this._dataSession = Database.GetSession();
}
return this._dataSession;
}
}
public override void Dispose() {
if(this._dataSession != null && this._dataSession.IsOpen) {
this._dataSession.Close();
}
base.Dispose ();
}
Is a clean way to keep alive a session for lazy-loading, and it trims down on some calls to the SessionFactory.
The downside is that the Session might get a bit bloated, but since it's only alive for the life of the Page, that doesn't seem like a big deal, and the lazy-loading and code-clarity is a bigger concern in most situations I think.
What do you guys think?