/// <summary> /// Intercepts a method. /// </summary> /// <param name="invocation">Method invocation arguments</param> public void Intercept(IInvocation invocation) { //If there isalready a running transaction (or no need to a db connection), just run the method if (UnitOfWorkScope.CurrentUow != null || !UnitOfWorkHelper.ShouldPerformUnitOfWork(invocation.MethodInvocationTarget)) { invocation.Proceed(); return; } using (var unitOfWork = IocHelper.ResolveAsDisposable <IUnitOfWork>()) { try { UnitOfWorkScope.CurrentUow = unitOfWork.Object; UnitOfWorkScope.CurrentUow.BeginTransaction(); try { invocation.Proceed(); UnitOfWorkScope.CurrentUow.Commit(); } catch (Exception ex) { try { UnitOfWorkScope.CurrentUow.Rollback(); } catch { } throw; } } finally { UnitOfWorkScope.CurrentUow = null; } } }
/// <summary> /// Intercepts a method. /// </summary> /// <param name="invocation">Method invocation arguments</param> public void Intercept(IInvocation invocation) { //If there is a running transaction, just run the method if (NhUnitOfWork.Current != null || !UnitOfWorkHelper.ShouldPerformUnitOfWork(invocation.MethodInvocationTarget)) { invocation.Proceed(); return; } try { NhUnitOfWork.Current = new NhUnitOfWork(_sessionFactory); NhUnitOfWork.Current.BeginTransaction(); try { invocation.Proceed(); NhUnitOfWork.Current.Commit(); } catch { try { NhUnitOfWork.Current.Rollback(); } catch { } throw; } } finally { NhUnitOfWork.Current = null; } }