Beispiel #1
0
        public Task Invoke(CommandEnvelope envelope, CancellationToken ct = default(CancellationToken))
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            if (_routes.TryGetValue(envelope.Command.GetType(), out Func <CommandEnvelope, CancellationToken, Task> handler))
            {
                return(handler(envelope, ct));
            }
            throw new InvalidOperationException($"Command {envelope.Command.GetType().Name} could not be invoked because no matching handler was found.");
        }
        internal CommandEnvelope(CommandEnvelope envelope)
        {
            if (envelope == null)
            {
                throw new ArgumentNullException(nameof(envelope));
            }

            Command       = (TCommand)envelope.Command;
            CommandId     = envelope.CommandId;
            CorrelationId = envelope.CorrelationId;
            SourceId      = envelope.SourceId;
            Metadata      = envelope.Metadata;
            Principal     = envelope.Principal;
        }