Beispiel #1
0
        /// <inheritdoc />
        /// <exception cref="T:System.ArgumentNullException" />
        /// <exception cref="T:ViennaNET.Mediator.Exceptions.UnsupportedTypeMessageException" />
        public async Task SendMessageAsync <TMessage>(TMessage message, CancellationToken cancellationToken = default)
            where TMessage : class, IMessage
        {
            await _preProcessorService.ExecuteAllPreProcessorsAsync(message, cancellationToken);

            try
            {
                switch (message)
                {
                case null:
                    throw new ArgumentNullException(nameof(message));

                case IEvent _:
                    await PublishEventAsync(message, cancellationToken);

                    break;

                case ICommand _:
                    await ExecuteCommandAsync(message, cancellationToken);

                    break;

                default:
                    throw new UnsupportedTypeMessageException($"Unsupported message type: {message.GetType()}.");
                }
            }
            catch (Exception e)
            {
                LogSendError(e);
                throw;
            }
        }