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:
1
public class NHManager<br />{<br /> public NHManager()<br /> {<br /> <span class="comments">//load config</span><br /><br /> <span class="comments">//create session factory</span><br /> }<br />}
1
public abstract class BusinessBase<br />{<br />private static NHManager _mgr = null;<br />[ThreadStatic()]<br />protected static NHManager Manager<br />{<br />get <br />{ <br />if( _mgr == null) <br />_mgr = new NHManager();<br />return _mgr;<br />}<br />}<br /><br />private ISession _session = null;<br />protected ISession CurrentSession<br />{<br />get<br />{<br />if( _session == null )<br />{<br /><span class="comments">//see if context contains it</span><br />if( HttpContext.Current[NHSESSION] == null ) <br /><span class="comments">//key is a constant</span><br />{<br /><span class="comments"><br />//this is the first access for this request, <br />//load the object<br /></span><br />_session = Manager.OpenSession();<br />HttpContext.Current[NHSESSION] = _session;<br />}<br />else<br />{<br /><span class="comments">//it exists in this request</span><br />_session = HttpContext.Current[NHSESSION] <br />as ISession;<br />}<br />}<br /><span class="comments">//make sure it's connected</span><br />if(! _session.IsConnected)<br />_session.ReConnect();<br />return _session;<br />}<br />}<br />}
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 )