开发者

Get the deserialized entity from outside the receiving handler in OpenRasta

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 wit开发者_StackOverflow社区h 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜