public void Should_Get_ConnectCommandHandler_When_Command_Is_Connect() { var command = new ConnectCommand(); var handler = CommandHandlerFactory.GetHandler(command); Assert.IsAssignableFrom <ConnectCommandHandler>(handler); }
public ICommandBus Send <T>(T command) where T : ICommand { var handler = _commandHandlerFactory.GetHandler <T>(); handler.Execute(command); return(this); }
public void InvokeCommandsQueue() { if (!commandsList.Any()) { throw new EmptyCommandsQueueException("No commands in queue"); } try { foreach (var command in commandsList) { var handler = commandHandlerFactory.GetHandler(command); var sendingMethod = handler.GetType().GetRuntimeMethods().FirstOrDefault(m => m.Name == "Handle"); if (sendingMethod != null) { sendingMethod.Invoke(handler, new object[] { command }); } else { throw new Exception($"Handle method not found on {handler.ToString()} object"); } } unitOfWork.SaveChanges(); } catch (TargetInvocationException ex) { throw ex.InnerException; } catch (Exception) { throw; } }
/// <summary> /// Simple direct call handler, can be replaced by event bus or any other messaging service /// </summary> /// <typeparam name="TCommand"></typeparam> /// <param name="command"></param> /// <returns></returns> public ICommandResult Send <TCommand>(TCommand command) where TCommand : ICommand { var handler = _commandHandlerFactory.GetHandler <TCommand>(); if (handler != null) { return(handler.Execute(command)); } throw new CommandHandlerNotFoundException(typeof(TCommand)); }
public void Execute <T>(T command) where T : Command { var handler = _commandHandlerFactory.GetHandler <T>(); if (handler == null) { throw new Exception("no handler registered"); } handler.Execute(command); }
public void Send <T>(T command) where T : ICommand { var handler = handlerFactory.GetHandler <T>(); if (handler == null) { throw new Exception("未找到对应的处理器"); } handler.Execute(command); }
public void Execute <T>(T command) where T : ICommand { var handler = _commandHandlerFactory.GetHandler(command); if (handler == null) { throw new InvalidOperationException($"Command `{command.GetType().FullName}` handler not found."); } handler.Handle(command); }
/// <summary> /// Sends the async. /// </summary> /// <returns>The async.</returns> /// <param name="command">Command.</param> /// <typeparam name="TCommand">The 1st type parameter.</typeparam> public async Task SendAsync <TCommand>(TCommand command) where TCommand : Command { var handler = commandHandlerFactory.GetHandler <TCommand>(); if (null == handler) { throw new UnregisteredHandlerException($"The handler of {typeof(TCommand).Name} is not registered"); } await handler.HandleAsync(command); }
public void Run() { while (true) { Console.Write(">"); var inputcommand = Console.ReadLine(); var handler = _handlerFactory.GetHandler(inputcommand); handler?.ProcessCommand(inputcommand); } }
public void Send <T>(T command) where T : Command { var handler = _commandHandlerFactory.GetHandler <T>(); if (handler != null) { handler.Execute(command); } else { throw new Exception(); } }
public void Send <T>(T command) where T : Command { var handler = _commandHandlerFactory.GetHandler <T>(); if (handler != null) { handler.Execute(command); } else { throw new UnregisteredDomainCommandException("no handler registered"); } }
public async Task Send <T>(T command) where T : Command { var handler = _commandHandlerFactory.GetHandler <T>(); if (handler != null) { await handler.Execute(command).ConfigureAwait(false); } else { throw new UnregisteredDomainEventException("no handler registered"); } }
public CommandResult Send <T>(T command) where T : Command { var handler = _commandHandlerFactory.GetHandler <T>(); if (handler != null) { return(handler.Execute(command)); } else { throw new UnregisteredDomainCommandException(string.Concat("No command handler registered for \"", command.ToString(), "\"")); } }
public async Task ProcessMessageAsync(Command command) { try { var handler = CommandHandlerFactory.GetHandler(command); ThrowsExceptionWhenHandlerIsNull(handler); await handler.ProcessAsync(command); } catch (Exception exception) { await ChatService.SendNoticeMessageAsync(command.ConnectionUid, exception.Message); } }
private ICommandHandler GetHandler(ICommand command) { Contract.Requires(command != null); Contract.Ensures(Contract.Result <ICommandHandler>() != null); try { // get handler from factory return(_handlerFactory.GetHandler(command.GetType())); } catch (Exception e) { // rethrow exception has a command handling exception throw new CommandHandlingException(command, e, "Could not get command handler."); } }
public async Task Dispatch <T>(T command) where T : class, ICommand { if (command == null) { throw new ArgumentNullException("command"); } var handler = _factory.GetHandler <T>(); if (handler == null) { throw new CommandHandlerNotFoundException($"command handler {nameof(T)} was not found"); } await handler.Invoke(command); }
public void Send <TCommand>(TCommand command) { ICommandHandler <TCommand> commandHandler = _commandHandlerFactory.GetHandler <TCommand>(); commandHandler.Process(command); }
public void CanGetHandlerForRegisteredCommand() { Assert.IsNotNull(_factory.GetHandler(typeof(Command1))); }
public async Task SendAsync <T>(T command) where T : Command { ICommandHandler <T> handler = _factory.GetHandler <T>(); await handler.ExecuteAsync(command); }