private void PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options) { var uow = _unitOfWorkManager.Begin(options); invocation.Proceed(); if (invocation.Method.ReturnType == typeof(Task)) { invocation.ReturnValue = AsyncHelper.WaitTaskAndActionWithFinally( (Task)invocation.ReturnValue, async() => await uow.CompleteAsync(), uow.Dispose ); } else { invocation.ReturnValue = AsyncHelper.CallReturnGenericTaskAfterAction( invocation.Method.ReturnType.GenericTypeArguments[0], invocation.ReturnValue, async() => await uow.CompleteAsync(), uow.Dispose ); } }