A wen scenario using the HTTP context, and a client that uses the Desktop. Use of the NHibernate framework
1 usingSystem;2 usingSystem.Collections.Generic;3 usingsystem.linq;4 usingsystem.text;5 6 usingNHibernate;7 usingnhibernate.cfg;8 usingsystem.web;9 Ten namespaceAgathas.Storefront.Repository.NHibernate.SessionStorage one { a /// <summary> - ///(after you have implemented the ability to save the session), you need some way to create the Session. - ///ability to use NHibernate to persist and retrieve business Entities. the /// </summary> - public classsessionfactory - { - //Nhibernate.isessionfactory created by the session factory + Private Staticisessionfactory _sessionfactory; - + //Initialize a at public Static voidInit () - { - //creating instances and configuring Assemblies -Configuration config =NewConfiguration (); -Config. Addassembly ("Agatha.Storefront.Repository.NHibernate"); - in //Log log4net - Log4net. Config.XmlConfigurator.Configure (); to + //Implementation Configuration - Config. Configure (); the * //Get Session Factory $_sessionfactory =Config. Buildsessionfactory ();Panax Notoginseng } - the //Get Session Factory + Private Staticisessionfactory getsessionfactory () a { the if(_sessionfactory = =NULL) + Init (); - $ return_sessionfactory; $ } - - Private StaticISession getnewsession () the { - returngetsessionfactory (). Opensession ();Wuyi } the - public StaticISession getcurrentsession () wu { -Isessionstoragecontainer Sessionstoragecontainer = about Sessionstoragefactory.getsessionstoragecontainer (); $ -ISession currensession =sessionstoragecontainer.getcurrentsession (); - - if(currensession = =NULL) a { +Currensession =getnewsession (); the Sessionstoragecontainer.store (currensession); - } $ the returncurrensession; the } the the } -}View Code
Software-develop-web