是RequestFilter验证客户端的依赖?客户端、RequestFilter

2023-09-06 11:25:48 作者:患得患失

我应该期待请求筛选验证(例如: FluentValidation )被触发时,instantiating通过咨询服务 AppHostBase.ResolveService<>

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);