コード例 #1
0
        public async Task <CommandResponse> SendAsync(ICommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            _userContext = command.UserContext;

            var handler      = _handlerResolver.ResolveHandler(command, typeof(ICommandHandlerAsync <>));
            var handleMethod = handler.GetType().GetMethod("HandleAsync", new[] { command.GetType() });
            var response     = await(Task <CommandResponseWithEvents>) handleMethod.Invoke(handler, new object[] { command });

            if (response == null)
            {
                return(null);
            }

            if (response.Events == null)
            {
                return(new CommandResponse(response.ValidationResult, response.ValidationResult));
            }

            await _eventProcessor.Process(response.Events, command);

            return(new CommandResponse(response.ValidationResult, response.ValidationResult));
        }
コード例 #2
0
        public async Task Consume(ConsumeContext <T> context)
        {
            _userContext.Set(context.Message.UserContext);
            var response = await HandleAsync(context.Message);

            _eventProcessor = _serviceProvider.GetService <IDomainEventProcessor>();
            await _eventProcessor.Process(response.Events, context.Message);
        }