从 OpenRasta 中的接收处理程序外部获取反序列化实体

发布于 2024-11-19 01:51:09 字数 386 浏览 2 评论 0原文

在 OpenRasta(版本 2.0.50727)中,如何从接收请求的处理程序外部获取反序列化实体的实例(在通过对象绑定传递之后)?具体一点;在发生异常的情况下,我希望 IOperationInterceptor 将 POST 实体返回给客户端,并添加一些错误信息,以便客户端可以更正信息并使用同一实体重新执行 POST 。

我查看了 IRequest.Entity,但这看起来像是实体的“原始”版本,这不是我想要的。我还查看了 IOperation.Inputs.First().Member (如在 IOperationInterceptor.BeforeExecute() 中收到的那样),但这看起来对于对象绑定器而不是我所追求的,即最终绑定和实例化的对象。

In OpenRasta (version 2.0.50727), how do I get to the instance of the deserialized entity (after being passed through object binding) from outside the handler that receives the request? To be specific; in the case of an exception, I want an IOperationInterceptor to return the POSTed entity to the client, with some added error information, so the client can correct the information and re-do the POST with the same entity.

I've looked at IRequest.Entity, but that looks like a "raw" version of the entity, which is not what I'm after. I've also looked at IOperation.Inputs.First().Member (as received in IOperationInterceptor.BeforeExecute()), but that too looks like something more useful for an object binder than for what I'm after, which is the finally bound and instantiated object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杆小烟枪 2024-11-26 01:51:09

我发现你可以像这样在 IOperationInterceptor.BeforeExecute 中重新构建对象:

public bool BeforeExecute(IOperation operation)
{
    var member = operation.Inputs.First();
    var bindingResult = member.Binder.BuildObject();
    var instance = bindingResult.Instance;
}

我还没有测试这会产生什么样的开销以及是否可以访问已经构建的实例,但是这个似乎正在发挥作用。如果有人对如何做得更好有想法,请添加答案。在接受这个作为解决方案之前,我会先暂时不回答这个问题。

I figured out that you can re-build the object in IOperationInterceptor.BeforeExecute like so:

public bool BeforeExecute(IOperation operation)
{
    var member = operation.Inputs.First();
    var bindingResult = member.Binder.BuildObject();
    var instance = bindingResult.Instance;
}

I haven't tested what kind of overhead this incurs and if it's possible to get to the already built instance, but this seems to be working. If anyone has ideas on how to do it better, please add an answer. I'll leave the question unanswered a while before accepting this as the solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文