Example #1
0
        public virtual R Handle(T query)
        {
            var response = default(R);

            try
            {
                _queryValidator.Validate(query);
                response = Task.Run(() => _handler.Handle(query)).Result;
                _bus.Response(response);
            }
            catch (QueryValidationException e)
            {
                _errorEventEmitter.EmitValidationFailed(query);
            }
            catch (QueryHandlerException e)
            {
                _errorEventEmitter.EmitHandlingFailed(query);
            }
            catch (Exception e)
            {
                _logger.Log("Exception while handling query[" + e.GetType() + "]: " + e.StackTrace, query);
                throw new QueryHandlerException();
            }
            return(response);
        }
Example #2
0
        public async void Handle(T command)
        {
            try
            {
                _validator.Validate(command);
                await Task.Run(() => _handler.Handle(command));

                _eventEmitter.Emit(command);
            }
            catch (CommandValidationException e)
            {
                _errorEventEmitter.EmitValidationFailed(command);
            }
            catch (CommandHandlerException e)
            {
                _errorEventEmitter.EmitHandlingFailed(command);
            }
            catch (Exception e)
            {
                _logger.Log("Exception while handling command[" + e.GetType() + "]: "
                            + e.StackTrace, command);
                throw new CommandHandlerException();
            }
        }