是RequestFilter验证客户端的依赖? [英] Is RequestFilter Validation client dependent?

查看:175
本文介绍了是RequestFilter验证客户端的依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该期待请求筛选验证(例如:<一href="https://github.com/ServiceStack/ServiceStack/wiki/Validation#fluentvalidation-for-request-dtos"相对=nofollow> FluentValidation )被触发时,<一个href="http://stackoverflow.com/questions/10571450/should-servicestack-be-the-service-layer-in-an-mvc-application-or-should-it-call/10572977#10572977">instantiating通过咨询服务 AppHostBase.ResolveService&LT;&GT;

Should I expect Request Filter Validation (e.g. FluentValidation) to be triggered when instantiating a reference service via AppHostBase.ResolveService<>?

到目前为止,我只成功地使用的键入客户 JsonServiceClient 在这种情况下,特别是)。

Thus far, I've only successfully received proper error responses to my C# application when using the typed clients (JsonServiceClient in this case specifically).

推荐答案

你是对的。如果您尝试使用 AppHostBase.ResolveService&LT; T&GT; 不执行任何的注册要求的过滤器。本质上,它只是解决了从APPHOST扶养容器中的服务,你回来只是服务实例。因此,你的校验器都不会被触发。

You are right. If you try use AppHostBase.ResolveService<T> it does not execute any of the registered request filters. Essentially it only resolves the Service from the AppHost dependancy container, you get back just the Service instance. Thus your validators aren't triggered.

由于@mythz指出可以使用的MQ入口点的API HostContext 与MQ请求过滤器执行调用的,因此具有运行验证。要做到这一点:

As @mythz points out you can use the MQ entry point API of the HostContext to execute the call with the MQ request filters and thus have the validation run. To do this:

HostContext.ServiceController.ExecuteMessage(new Message<T>(requestDto), httpReq);

@mythz还注意到,您可以执行只用一个DTO,而不是来确定服务和操作方法来调用一个服务,而是以类似的方式来 AppHostBase.ResolveService&LT; T&GT; 它的的触发请求过滤器。用法:

@mythz also notes you can execute a service using just a DTO, rather than having to determine the service and handling method to call, but in a similar fashion to AppHostBase.ResolveService<T> it doesn't trigger the request filters. Usage:

HostContext.ServiceController.Execute(requestDto, httpReq)

ServiceStack V3:

GetAppHost().Config.ServiceManager.ServiceController.ExecuteMessage(new Message<T>(requestDto), httpReq);

这篇关于是RequestFilter验证客户端的依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆