예제 #1
0
        public async Task <GrpcResponseEnvelope <TResponse> > ProcessRequestAsync <TRequest, TResponse>(TRequest request, CqrsInfo info, CancellationToken cancellationToken)
        {
            if (info.IsCommand)
            {
                if (info.IsAsync)
                {
                    if (info.RspType != null)
                    {
                        var cmd = request as IAsyncCommand <TResponse>;
                        var rsp = await _commandDispatcher.DispatchAsync(cmd, cancellationToken);

                        return(CreateResponseEnvelope(rsp));
                    }
                    else
                    {
                    }
                }
                else
                {
                    if (info.RspType != null)
                    {
                        var cmd = request as ICommand <TResponse>;
                        var rsp = await Task.Run(() =>
                        {
                            return(_commandDispatcher.Dispatch(cmd));
                        }, cancellationToken);

                        return(CreateResponseEnvelope(rsp));
                    }
                }
            }

            if (info.IsQuery)
            {
                if (info.IsAsync)
                {
                    var query = request as IAsyncQuery <TResponse>;
                    var rsp   = await _queryProcessor.HandleAsync(query, cancellationToken);

                    return(CreateResponseEnvelope(rsp));
                }
                else
                {
                    var query = request as IQuery <TResponse>;
                    var rsp   = await Task.Run(() =>
                    {
                        return(_queryProcessor.Handle(query));
                    }, cancellationToken);

                    return(CreateResponseEnvelope(rsp));
                }
            }

            // not supported
            return(CreateResponseEnvelopeError <TResponse>("Not supported request."));
        }
예제 #2
0
 private ActionResult <TResult> HandleRequestProcedure()
 {
     try
     {
         var req = Activator.CreateInstance <TQuery>();
         var rsp = _queryProcessor.Handle(req);
         if (rsp == null)
         {
             return(NotFound());
         }
         return(Ok(rsp));
     }
     catch (Exception e)
     {
         return(new BadRequestObjectResult(e.ToValidationErrorResponse()));
     }
 }
예제 #3
0
        private ActionResult <TResult> HandleRequestProcedure(TQuery req)
        {
            // bind query parameters
            HttpContext.BindQueryParams(req);

            try
            {
                var rsp = _queryProcessor.Handle(req);
                if (rsp == null)
                {
                    return(NotFound());
                }
                return(Ok(rsp));
            }
            catch (Exception e)
            {
                return(new BadRequestObjectResult(e.ToValidationErrorResponse()));
            }
        }