Hi all,
I am currently working on an enterprise solution, which hosts several applications and due to that I implemented NHibernate to work with several session factories. I created a custom section like:
<hibernate-sessionFactories>
<sessionFactories>
<clear/>
<add name="Server1" factoryConfigPath="~/SessionFactoryConfigurations/Server1.config"/>
<add name="Server2" factoryConfigPath="~/SessionFactories/Server2.config" />
</sessionFactories>
</hibernate-sessionFactories>
I implemented a lazy singleton session provider which instantiates these session factories on demand.
I am using the repository pattern. Within a persistence method, to get the current NHibernate session, I now can call something like
ISession session = sessionProvider.GetCurrentSessionFrom(sessionFactoryConfigName);
So depending on the session factory config name I get the correct session. For transactional things I would like to use the System.Transactions.TransactionScope, so I can have "nested" transactions like:
using(var scope = new TransactionScope(System.Transactions.TransactionScopeOption.Required))
{
using(var scope = new TransactionScope(System.Transactions.TransactionScopeOption.Required))
{
}
}
Would that work without problems? Since I'm working with multiple server, how does the transaction scope know on which server to enlist the transaction? Are there better ways to do transaction management with easy handling of nested transactions?
Do you understand my question anyway? ;)