private bool TryBegin(IInvocation invocation) { var method = invocation.MethodInvocationTarget ?? invocation.Method; var attribute = method.GetCustomAttributes(typeof(TransactionAttribute), false).FirstOrDefault(); if (attribute is TransactionAttribute transaction) { _unitOfWork = _unitOfWorkManager.Begin(transaction.Propagation, transaction.IsolationLevel); return(true); } return(false); }
private async void InterceptTransaction(IInvocation invocation, MethodInfo method) { try { var transaction = method.GetAttribute <TransactionAttribute>(); _unitOfWork = _unitOfWorkManager.Begin(transaction.Propagation, transaction.IsolationLevel); invocation.Proceed(); dynamic returnValue = invocation.ReturnValue; if (returnValue is Task) { returnValue = await returnValue; } if (returnValue is IResponseOutput res && !res.Success) { _unitOfWork.Rollback(); } else { _unitOfWork.Commit(); } }