我应该将视图模型重用为 REST 服务中的资源吗?
我正在开发一个应用程序,它将保留视图模型以供 UI 使用。对于 REST 服务,直接将视图模型重新用作资源是否是一个好主意,或者我应该创建特定的资源类并使用 AutoMapper 之类的东西将视图模型映射到资源上?
I'm developing an application that will persist view models for consumption by the UI. For a REST service, is it considered a good idea to re-use view models directly as resources, or should I create specific resource classes and use something like AutoMapper to map the view models onto resources?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法说出 openrasta 的曲调,但在 REST 的背景下,你拥有资源和表示。该资源应该能够处理 HTTP 动词的语义以及它们在域模型中的意义。客户端通常与资源的表示形式(XML、HTML)进行交互,这导致人们认为资源和控制器是同一件事。我不同意。 MVC 作为面向客户端的范例对我来说很有意义,虽然有些人认为它是语义,但我只是不明白 REST 中如何拥有视图和模型。
简而言之,我将创建新的资源类,这些资源类可能会与控制器的大部分进行通信或重用,以便完成从 REST 角度来看有意义的事情。
I can't speak to the tune of openrasta, but in the context of REST you have resources and representations. The resource should be capable of handling the semantics of HTTP verbs and how they make sense in your domain model. Clients generally interact with representations of your resources (XML, HTML) and this leads people to think that a resource and a controller are the same thing. I disagree. MVC makes sense to me as a client oriented paradigm and while some argue that it is semantics, I just don't see how you have views and models in REST.
In short, I would create new resource classes that perhaps talk to or re-use large parts of, your controllers in order to accomplish what makes sense from the REST perspective.