コード例 #1
0
        private void PerformAsyncUow(IMethodInvocation invocation)
        {
            var uow = _unitOfWorkManager.Begin();

            invocation.Proceed();

            if (invocation.MethodInvocationTarget.ReturnType == typeof(Task))
            {
                invocation.ReturnValue = AsyncHelper.AwaitTaskWithPostActionAndFinally(
                    (Task)invocation.ReturnValue,
                    async() => await uow.CommitAsync(),
                    exception => uow.Dispose()
                    );
            }
            else //Task<TResult>
            {
                invocation.ReturnValue = AsyncHelper.CallAwaitTaskWithPostActionAndFinallyAndGetResult(
                    invocation.MethodInvocationTarget.ReturnType.GenericTypeArguments[0],
                    invocation.ReturnValue,
                    async() => await uow.CommitAsync(),
                    exception => uow.Dispose()
                    );
            }
        }