コード例 #1
0
        public async Task HandleAsync(TCommand command)
        {
            if (command.GetType().GetCustomAttribute <TransactedCommandAttribute>() == null)
            {
                await Decorated.HandleAsync(command);

                return;
            }

            suspendExecutionStrategy.Suspend();

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    await Decorated.HandleAsync(command);

                    scope.Complete();
                }
                catch (Exception exception)
                {
                    scope.Dispose();
                    loggingService.ErrorException("Failed to complete transaction", exception);
                    throw;
                }
                finally
                {
                    suspendExecutionStrategy.Unsuspend();
                }
            }
        }