ServiceStack Rest - 复杂的 uri 层次结构 [英] ServiceStack Rest - Complex uri hierarchies

查看:43
本文介绍了ServiceStack Rest - 复杂的 uri 层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C# 框架servicestack"(http://www.servicestack.net/)创建一个休息网络服务,但我在试图弄清楚如何支持更复杂的休息层次结构时遇到了问题

I'm creating a rest webservice using the c# framework 'servicestack' (http://www.servicestack.net/) and I'm having issues trying to figure out how to support more complex rest hierarchies

而且我正在配置各种路由并且它完美运行

And I'm configuring various routes and it works perfectly

Routes
    .Add<MerchantDto>("/merchants")
    .Add<MerchantDto>("/merchants/{id}")
    .Add<MerchantDto>("/merchantGroups/{merchantGroupId}/merchants")
    .Add<MerchantDto>("/merchantGroups/{merchantGroupId}/merchants/{id}")

    .Add<StoreDto>("/stores")
    .Add<StoreDto>("/stores/{id}")
    .Add<StoreDto>("/merchants/{merchantId}/stores")
    .Add<StoreDto>("/merchants/{merchantId}/stores/{id}");

这一切正常.这个问题是这样做的....

This all works fine. This problem is doing this....

    .Add<StoreDto>("/merchantGroups/{merchantGroupId}/merchants/{merchantId}/stores/{id}

这里的问题是 StoreDto 对象只包含 MerchantId,它不包含 MerchantGroupId,所以这不起作用.

The problem here is that the StoreDto object only contains a MerchantId, it does not contain a MerchantGroupId so this wouldn't work.

一种解决方案是将 MerchantGroupId 添加到 DTO,但问题是我正在与其他一些 WCF 服务共享 DTO,如果我在 StoreDto 中有一个 MerchantGroupId 属性,但在此期间从未填充过,这可能会造成混淆检索操作.

One solution would be to add the MerchantGroupId to the DTO but the problem is that I am sharing the DTO with some other WCF services and it might be confusing if I were have a MerchantGroupId property in the StoreDto which is never populated during a retrieval operation.

另外,我认为这会出现在不同的地方,所以我希望有更好的方法来做到这一点.

Plus I see this as cropping up at different places so I was hoping there was a better way to do it.

有什么建议吗?

推荐答案

就像@myth 说的那样,我只是通过尝试生成类似 MVC 的 url 路径使事情变得复杂.

Like @myth says I am just making things complicated by trying to generate MVC-like url paths.

我坚持按原样使用 uri 路径.

I am sticking to using the uri paths as is.

这篇关于ServiceStack Rest - 复杂的 uri 层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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