Ejemplo n.º 1
0
        public ICommandHandler <TCommand> GetCommandHandler <TCommand>(TCommand command)
            where TCommand : ICommand
        {
            ICommandHandler <TCommand> handler;

            try
            {
                handler = (ICommandHandler <TCommand>)_commandHandlers.SingleOrDefault(x => x.CanHandle(command));
            }
            catch (InvalidOperationException)
            {
                throw new ArgumentException($"More than one type found that can handle {command.GetType()} commands");
            }

            if (handler == null)
            {
                handler = _commandHandlerFactory.CreateHandlerFor(command);
            }

            if (handler == null)
            {
                throw new ArgumentException($"Could not find any handler to handle command of type {command.GetType()}");
            }

            return(handler);
        }
Ejemplo n.º 2
0
        private void WhenMarkingDrinksAsServed()
        {
            var commandHandler = _commandHandlerFactory.CreateHandlerFor <IMarkDrinksServedCommand>(_markDrinksServedCommand);

            _tab = (Tab)commandHandler;
        }
Ejemplo n.º 3
0
 private void ConfigureCommandHandlerFactory(ICommandHandlerFactory commandHandlerFactory)
 {
     commandHandlerFactory.CreateHandlerFor(Arg.Is <TCommand>(command => command.AggregateId == AggregateId)).Returns((ICommandHandler <TCommand>)CommandHandler);
     commandHandlerFactory.CreateHandlerFor(Arg.Is <TCommand>(command => command.AggregateId == _aggregateId2)).Returns((ICommandHandler <TCommand>)CommandHandler2);
 }