Example #1
0
        /// <summary>
        /// This method handles the command. It just ensures that no other request exists with the same ID, and if this is the case
        /// just enqueue the original inner command.
        /// </summary>
        /// <param name="message">IdentifiedCommand which contains both original command & request ID</param>
        /// <param name="cancellationToken"></param>
        /// <returns>Return value of inner command or default value if request same ID was found</returns>
        public async Task <TResponse> Handle(IdentifiedCommand <TResponse, TCommand> message, CancellationToken cancellationToken = default)
        {
            await _requestManager.CreateAsync(message.RequestId, _suppressDuplicatedError);

            // Send the embedded business command to mediator so it runs its related CommandHandler
            return(await _mediator.Send(message.Command, cancellationToken));
        }
Example #2
0
        /// <summary>
        /// Dispatch a new Command
        /// </summary>
        /// <typeparam name="TCommand"></typeparam>
        /// <param name="command">The Command is going to be sent</param>
        /// <param name="event">The IntegrationEvent</param>
        protected async Task <bool> DispatchAsync <TCommand>(TCommand command, IntegrationEvent @event)
            where TCommand : Command <bool>
        {
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            command.AppendTraceMetadata(@event);

            IRequest <bool> cmd;

            if (_supportIdempotencyCheck)
            {
                cmd = new IdentifiedCommand <bool, TCommand>(@event.RequestId, command);
            }
            else
            {
                cmd = command;
            }

            return(await _mediator.Send(cmd).ConfigureAwait(false));
        }