using System; using s=System; using nh=NHibernate; namespace DalNH { public static class SessionFactory { static object lockdummy = new object(); static nh.ISessionFactory _inner; static nh.ISessionFactory CreateInnerSessionFactory(string strConnection) { log4net.Config.XmlConfigurator.Configure(); nh.Cfg.Configuration aConfiguration = new NHibernate.Cfg.Configuration(); // aConfiguration.Configure(); aConfiguration.SetProperty(nh.Cfg.Environment.Dialect , "NHibernate.Dialect.MsSql2005Dialect" ); aConfiguration.SetProperty(nh.Cfg.Environment.ConnectionDriver , "NHibernate.Driver.SqlClientDriver" ); aConfiguration.SetProperty(nh.Cfg.Environment.ConnectionString , strConnection); aConfiguration.SetProperty(nh.Cfg.Environment.ConnectionDriver , "NHibernate.Driver.SqlClientDriver"); aConfiguration.SetProperty(nh.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"); s.Reflection.Assembly aAssembly = typeof(SessionFactory).Assembly; aConfiguration.AddAssembly(aAssembly); return aConfiguration.BuildSessionFactory(); } // static SessionFactory() // { // //could call init from here, but then errors are really hard to track down. // _inner = CreateInnerSessionFactory(); // } public static nh.ISession OpenSession(string strConnection) { lock(lockdummy) { if(_inner ==null) _inner = CreateInnerSessionFactory(strConnection); } return _inner.OpenSession(); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)