/// <summary> /// 同步拦截器事务处理 /// </summary> /// <param name="invocation"></param> /// <param name="attribute"></param> private void InternalInterceptSynchronous(IInvocation invocation, [NotNull] UnitOfWorkAttribute attribute) { try { _unitOfWork.BeginTransaction(sharedToCap: attribute.SharedToCap); invocation.Proceed(); _unitOfWork.Commit(); } catch (Exception ex) { _unitOfWork.Rollback(); throw new Exception(ex.Message, ex); } finally { _unitOfWork.Dispose(); } }
/// <summary> /// 异步拦截器事务处理-无返回值 /// </summary> /// <param name="invocation"></param> /// <param name="attribute"></param> /// <returns></returns> private async Task InternalInterceptAsynchronous(IInvocation invocation, [NotNull] UnitOfWorkAttribute attribute) { try { _unitOfWork.BeginTransaction(sharedToCap: attribute.SharedToCap); invocation.Proceed(); var task = (Task)invocation.ReturnValue; await task; await _unitOfWork.CommitAsync(); } catch (Exception ex) { await _unitOfWork.RollbackAsync(); throw new Exception(ex.Message, ex); } finally { _unitOfWork.Dispose(); } }