private void HandleCommand <TCommand>(RingCommandContext context, ICommand command) where TCommand : ICommand { var handlerType = _commandRegister.FindHandlerType <TCommand>(); if (handlerType == null) { var message = $"命令[{command.GetType().Name}]的命令执行器没有找到"; _logger.LogInformation(message); throw new DomainException(DomainCode.CommandHandlerNotExists, message); } ICommandHandler <TCommand> handler; try { handler = _commandHandlerFactory.Create <TCommand>(handlerType); } catch (Exception ex) { var message = $"命令[{command.GetType().Name}]的命令执行器无法创建,原因:{ex.Message}"; _logger.LogInformation(message); throw new DomainException(DomainCode.CommandHandlerCannotCreate, message); } handler.Handle(context, (TCommand)command); }
public RingCommandBusinessHandler( IContextCache contextCache , ICommandHandlerFactory commandHandlerFactory , IEventStore eventStore , IEventBus eventBus , ICommandRegister commandRegister , IAggregateRootRebuilder aggregateRootRebuilder , ILoggerFactory loggerFactory , int maxHandleCount) : base(maxHandleCount) { this.context = new RingCommandContext(contextCache, aggregateRootRebuilder); this._contextCache = contextCache; this._commandHandlerFactory = commandHandlerFactory; this._eventStore = eventStore; this._eventBus = eventBus; this._commandRegister = commandRegister; this._aggregateRootRebuilder = aggregateRootRebuilder; this._logger = loggerFactory.CreateLogger <RingCommandBusinessHandler>(); }