title: NHibernate/NInject - Update is not executed right after user submit a form
body: <p>I am in a project which uses below framework</p>
  
  <ul>
  <li>ASP.NET MVC4</li>
  <li>NHibernate as an ORM</li>
  <li>NInject as an IoC to manage dependencies and do DI</li>
  </ul>
  
  <p>The issue is that after user updated an entity and submitted the form, he must wait about 20 seconds to have correct data loaded. Also this time the changes are saved into database (SQL Server)</p>
  
  <p>We have manage NHibernate ISession object in RequestScope but found out that the <strong>Deactivation method is not calling</strong> when MVC redirect from edit to list screen.</p>
  
  <p>Below is main part of the NInject module for NHibernate:</p>
  
  <p><strong>Load method:</strong></p>
  
  <pre><code>Bind&lt;ISession&gt;()
              .ToMethod(c =&gt; c.Kernel.Get&lt;ISessionFactory&gt;().OpenSession(interceptor))
              .InRequestScope()
              .OnActivation(SetupSession())
              .OnDeactivation(CommitOrRollback)
  
  
  private Action&lt;ISession&gt; SetupSession()
      {
          _logger.Debug("OnActivation");
  
          return s =&gt;
          {
              s.BeginTransaction(IsolationLevel.ReadCommitted);
              s.FlushMode = FlushMode.Commit;
          };
      }
  
      private void CommitOrRollback(ISession session)
      {
          _logger.Debug("OnDeactivation");
  
          if (!session.Transaction.IsActive)
          {
              return;
          }
  
          try
          {
              session.Transaction.Commit();
              session.Flush();
              _logger.Debug("Session committed successfully");
          }
          catch (Exception ex)
          {
              session.Transaction.Rollback();
              throw new CommitDataException(ex);
          }
      }
  </code></pre>
  
  <p>Thanks for any advice !</p>