NHibernate/NInject - Update is not executed right after user submit a form

76 Views Asked by At

I am in a project which uses below framework

  • ASP.NET MVC4
  • NHibernate as an ORM
  • NInject as an IoC to manage dependencies and do DI

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)

We have manage NHibernate ISession object in RequestScope but found out that the Deactivation method is not calling when MVC redirect from edit to list screen.

Below is main part of the NInject module for NHibernate:

Load method:

Bind<ISession>()
            .ToMethod(c => c.Kernel.Get<ISessionFactory>().OpenSession(interceptor))
            .InRequestScope()
            .OnActivation(SetupSession())
            .OnDeactivation(CommitOrRollback)


private Action<ISession> SetupSession()
    {
        _logger.Debug("OnActivation");

        return s =>
        {
            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);
        }
    }

Thanks for any advice !

1

There are 1 best solutions below

0
On BEST ANSWER

With confident on the code we implemented after some investigations with adding more logs. Then we detect there is a new release of Ninject.Web.Common

Upgrade from Ninject.Web.Common 3.2.0.0 to

3.2.3.0

and application works. Will check what has been changed in the lib.