devonl wrote:
i've done exactly what you are asking, although I'm not completely satisfied with the final solution. I have a singleton in my DAO layer that wraps the ISessionFactory for NH. Then I've created an AbstractDAO that acts as a facade and uses the singleton for access to the NH session. Then I implement DAOs as appropriate that extend the AbstractDAO.
in my ASP.NET pages I simply create a new instance to the apropriate DAO and use it to create, read, update, delete, etc...
the disadvantage i see is that i have to manually open and close sessions (my DAO has an overloaded constructor that allows me to specific whether or not to open a session). that isn't so bad.
however, i also have designed a system that uses a single large DAO that is composed into a System.Web.UI.Page class that all of my pages inherit from. This makes it _really_ ease to use the facade I've created. opening ov the session happens at each context_start() and closing the session happens at each context_end().
the individual DAOs follow OO theory in a more formal way, but the single DAO is _really_ easy. did i mention how easy it was? :)
-devon
Thanks for the info and tips devon.
By the way I did not mention on previous post that I'm currently testing NHibernate session. sorry for that. I implemented also a single ton class for Sesssion Factory that holds the static session. then I have an abstract DAO BaseDAO(Create,Delete,Update,List) that suppose to be inherited by my DAOs like UserDAO,GroupDAO,AuditDAO class. Then I have Biz a classes that calls DAO(i.e. UserBIz calls UserDAO etc.). The main purpose of my Biz layer is to perform and control transaction that will calls multiple DAO by wrapping it one COM+ Transaction.(i.e. UserBiz calls UserDAO.Create() and AuditDAO.Create() method)
See illustration below:
-Biz Class-->
<BeginTransaction>
-->DAO1 Class --Inhetrit--> <BaseDAO> --GetSession--> <SessionFac>
-->DAO2 Class --Inhetrit--> <BaseDAO> --GetSession--> <SessionFac>
-->DAOn class. --Inhetrit--> <BaseDAO> --GetSession--> <SessionFac>
<CommitTransaction>
Since I have an open session, everytime there's a call in DAO method it checks if there is an open session in Session Factory, if there's an open then get it from static variable Session else open a new one.
The problem is this: if I encountered an error like deleting a record with a foreign key to another table or any database access error, the ASP.Net page does not refresh, the error retains even if I changed it to another page.
thanks :-)
Eugene