http://fabiomaulo.blogspot.com/2009/09/configure-sessionfactory-providers.html
2010/1/19 csetzkorn <[email protected]> > Dear all, > > I am a bit stuck and would like some help please. > > I am using DAOs in a web application (ASP.NET MVC within controllers) > served by two dao factories which access two separate databases. > > The DAOs use this class: > > public class NHibernateHelper > { > private static ISessionFactory sessionFactory; > > public static ISessionFactory SessionFactory > { > get > { > if (sessionFactory == null) > { > sessionFactory = new Configuration().Configure > ().AddAssembly("Bla").BuildSessionFactory(); > } > return sessionFactory; > } > } > > public static ISession OpenSession() > { > return SessionFactory.OpenSession(); > } > > public static ISession GetCurrentSession() > { > if (!CurrentSessionContext.HasBind(SessionFactory)) > { > CurrentSessionContext.Bind(SessionFactory.OpenSession > ()); > } > return SessionFactory.GetCurrentSession(); > } > > public static void DisposeSession() > { > var session = GetCurrentSession(); > session.Close(); > session.Dispose(); > } > > public static void BeginTransaction() > { > GetCurrentSession().BeginTransaction(); > } > > public static void CommitTransaction() > { > var session = GetCurrentSession(); > if (session.Transaction.IsActive) > session.Transaction.Commit(); > } > > public static void RollbackTransaction() > { > var session = GetCurrentSession(); > if (session.Transaction.IsActive) > session.Transaction.Rollback(); > } > } > > This is all no problem if I only use one database as I can just define > one hibernate-configuration section in my Web.config. I am just > wondering what I can do to define the connection strings for two or > more databases. I could use something like this when the singleton > sessionFactory is accessed: > > SessionFactory sf = new Configuration() > .Configure("/path/to/config.cfg.xml") > .BuildSessionFactory(); > > or this: > > cfg.SetProperty("connection.connection_string", > get_connection_string_from_other_web_config); > cfg.BuildSessionFactory(); > > However, this seems all a bit 'dirty' (I did not try it yet as well). > I would also like to use my DAO classes etc. in other applications > (e.g. console application). Any feedback would be very much > appreciated. Many thanks in advance. > > Best wishes, > > Christian > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > > > -- Fabio Maulo--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
