Thursday, April 28, 2005

NHibernate and ASP.NET - Part 2

After some toying around, I have my first object Saving/Updating/Deleting and using a GetAll method to bind to a Datagrid. All of this with about 5 or 6 lines of UI code! Yummy!

I still have some design concerns to wrinkle out, though. Here's how I have mine set up:

public class NHManager
{
public NHManager()
{
//load config

//create session factory
}
}


public abstract class BusinessBase
{
private static NHManager _mgr = null;
[ThreadStatic()]
protected static NHManager Manager
{
get
{
if( _mgr == null)
_mgr = new NHManager();
return _mgr;
}
}

private ISession _session = null;
protected ISession CurrentSession
{
get
{
if( _session == null )
{
//see if context contains it
if( HttpContext.Current[NHSESSION] == null )
//key is a constant
{

//this is the first access for this request,
//load the object

_session = Manager.OpenSession();
HttpContext.Current[NHSESSION] = _session;
}
else
{
//it exists in this request
_session = HttpContext.Current[NHSESSION]
as ISession;
}
}
//make sure it's connected
if(! _session.IsConnected)
_session.ReConnect();
return _session;
}
}
}


Is there anything glaringly wrong about the above sample? I am expecting a little flaming due to the [ThreadStatic()] in my ASP.NET Application, but is it really that bad since my manager object is WORM (Write Once Read Many) ???

I welcome suggestions and comments (now that they will actually work :P )
#    Comments [0] | Trackback
Tracked by:
"phentermine" (phentermine) [Trackback]
"viagra" (viagra) [Trackback]
"casinos" (casinos) [Trackback]
"Online Casino" (Online Casino) [Trackback]
"buy prozac" (buy prozac) [Trackback]
"blackjack" (blackjack) [Trackback]
"tramadol" (tramadol) [Trackback]
"phentermine" (phentermine) [Trackback]
"cialis" (cialis) [Trackback]
"online casino" (online casino) [Trackback]
"ultram" (ultram) [Trackback]
"casinos" (casinos) [Trackback]
"online blackjack" (online blackjack) [Trackback]
"online casinos" (online casinos) [Trackback]
"casino" (casino) [Trackback]
"online casino gambling" (online casino gambling) [Trackback]
"poker" (poker) [Trackback]
"online casino" (online casino) [Trackback]
"phentermine" (phentermine) [Trackback]
"phentermine" (phentermine) [Trackback]
"online casino" (online casino) [Trackback]
"poker" (poker) [Trackback]
"ambien online" (ambien online) [Trackback]
"casino game" (casino game) [Trackback]
"online poker" (online poker) [Trackback]
"online casino directory" (online casino directory) [Trackback]
"order phentermine" (order phentermine) [Trackback]
"zithromax" (zithromax) [Trackback]
"order phentermine" (order phentermine) [Trackback]
"online casino" (online casino) [Trackback]
"phentermine" (phentermine) [Trackback]
"ambien" (ambien) [Trackback]
"roulette" (roulette) [Trackback]
"phentermine" (phentermine) [Trackback]
"phentermine" (phentermine) [Trackback]
"casinos" (casinos) [Trackback]
"blackjack" (blackjack) [Trackback]
"online casino" (online casino) [Trackback]
"phentermine" (phentermine) [Trackback]
"craps" (craps) [Trackback]
Comments are closed.
New York Hotel - Savings - Mortgage - Internet Marketing