Session-in-view and TransactionScope

We have an asp.net webforms application using NHibernate. Here are some features:

  • We need distributed transactions because we write to the database, as well as to the queue.
  • Since this is a web application, we use the recommended session in presentation template. We have an HTTPModule that opens an NHibernate session in the BeginRequest event and closes it at EndRequest.
  • In the request flow, we have several separate points when we need to perform transactional work. For this we use TransactionScope.

So basically this happens (pseudo-code):

using(var session = sessionFactory.CreateSession()){
  using(var tx1 = new TransactionScope(){
    //work work work
    tx1.Complete();
  }

  //other work

  using(var tx2 = new TransactionScope(){
    //work work work
    tx2.Complete();
  }
}

However, now we are in a situation where we see a lot of failures associated with connecting to the database. Some studies have given us two suggestions:

  • NHibernate

:

  • NHibernate TransactionScope. NHibernate?
  • TransactionScope, Session-in-view?
+3
2
  • NH (session.BeginTransaction())
  • NH TransactionScope
  • TransactionScope.
+4

ncommon framework, NHibernate TransactionScope UnitOfWorkScope; , .

0

Source: https://habr.com/ru/post/1781448/


All Articles