コード例 #1
0
 protected virtual async Task RunInternalAsync(
     CommandContext context, CancellationToken cancellationToken = default)
 {
     using var _1 = context;
     using var _2 = context.Activate();
     try {
         var command  = context.UntypedCommand;
         var handlers = HandlerResolver.GetCommandHandlers(command.GetType());
         context.ExecutionState = new CommandExecutionState(handlers);
         if (handlers !.Count == 0)
         {
             await OnUnhandledCommandAsync(command, context, cancellationToken).ConfigureAwait(false);
         }
         await context.InvokeRemainingHandlersAsync(cancellationToken).ConfigureAwait(false);
     }
     catch (OperationCanceledException) {
         context.TrySetCancelled(
             cancellationToken.IsCancellationRequested ? cancellationToken : default);
コード例 #2
0
    protected virtual async Task RunInternal(
        CommandContext context, CancellationToken cancellationToken = default)
    {
        var activationScope = context.Activate();

        try {
            var command  = context.UntypedCommand;
            var handlers = HandlerResolver.GetCommandHandlers(command.GetType());
            context.ExecutionState = new CommandExecutionState(handlers);
            if (handlers !.Count == 0)
            {
                await OnUnhandledCommand(command, context, cancellationToken).ConfigureAwait(false);
            }
            await context.InvokeRemainingHandlers(cancellationToken).ConfigureAwait(false);
        }
        catch (Exception e) {
            context.SetResult(e);
        }
        finally {
            context.TryComplete(cancellationToken);
            activationScope.Dispose();
            await context.DisposeAsync().ConfigureAwait(false);
        }
    }