我们能否在MVC架构中实现SOA风格
可以有一个基于 MVC 的基于 Web 的架构布局,其中 SOA 是架构风格。或者换句话来说,服务是否可以成为 MVC 的 M、V、C 的一部分。如果是,那么它们各自可以包含哪些类型的服务。另外,你能给我一个现实世界的例子吗?
Is to possible to have a layout for web-based architecture based on MVC where SOA is the architectural style. Or to rephrase, can services be part of the M,V, C of MVC.If so, what kinds of services can be included in each of them. Also, can you give me a real world example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 SOA 应用程序中,通常不包括前端(表示层)。您在 MVC 应用程序中使用这些服务,或者更好的是在 MVC 应用程序使用的单独“模型”项目中使用这些服务。
数据访问->业务逻辑->服务->型号-> MVC 的
要点是使用服务围绕应用程序的基础创建抽象,以允许多个客户端使用这些服务。
In a SOA application you are typically not including the front end (presentation layer). You are consuming those services in your MVC application, or better yet in a separate "model" project that the MVC application uses.
Data Access -> Business Logic -> Services -> Models -> MVC
The point is to use the services to create an abstraction around the base of your application to allow for multiple clients to consume those services.
我倾向于将客户端/表示层中表示的模型称为 ViewModel,它只是模型的表示层视图。不是实际的域模型。这在 SOA 中是必需的,因为模型使用者的上下文经常发生变化
。在 SOA 中,我们尝试获得契约的规范模式,因为很可能并非所有客户端现在和将来都需要这种模式。将来将需要完全相同的模型视图。
因此,无论是 Web 客户端、服务客户端还是桌面客户端,如果您将 MVC 中的模型视为 ViewModel,这允许您将表示层事物从服务层事物中抽象出来,并且您更接近规范模式。
所以一个例子查看>>控制器>> ViewModel(模型)>>数据合同>>服务
如何构建这样的服务堆栈的示例可以在这里找到:
SOA 设计模式
决定是采用 REST 架构还是完整的 WS-* SOAP 是一个单独的问题,不应影响您选择 MVC 作为表示模式。
当然,可能存在其他限制,无法使用其中之一。
在 Microsoft 平台上为新的或企业 Web 开发选择表示模式是一项艰巨的任务,在我看来只有三种;视图模型、模型-视图-呈现器 (MVP) 或 ASP.NET MVC(Model2 衍生品)。
您可以在此处阅读完整文章ASP.NET MVC 模式
I tend to term the Model as represented in the client/presentation layer as the ViewModel, it is simply the presentation layers view of the model. Not the actual Domain model.This is needed in a SOA as the context of the consumer of the Model changes often
In SOA`s we try to get to a canonical schema for the contract, as it is quite likely that not all clients now and in the future will require the exact same view of the model.
Thus be it a web client, service client or a desktop client, if you think of the Model in MVC as the ViewModel, this allows you to abstract presentation layer things away from Service layer things, and you get closer to a canonical schema.
So an example View >> Controller >> ViewModel(Model) >> Data Contract >> Service
Examples of how to build a service stack like this can be found here:
SOA Design Pattern
The decision of whether to go with a REST architecture or a full WS-* SOAP is a separate concern and should not affect your choice of MVC as a presentation pattern.
There may of course be other constraints that preclude the use of one or the other.
Choosing a presentation pattern for a new or enterprise web development on the Microsoft platform is a daunting task, in my opinion there are only three; View Model, Model-View-Presenter (MVP) or ASP.NET MVC (a Model2 derivative).
You can read the full article here ASP.NET MVC Patterns
这取决于 SOA 的含义。如果您指的是 WS-* 标准,我不会推荐 MVC,因为您需要编写大量管道才能使其正常工作。
如果您正在寻找类似 REST 服务的东西,那么 MVC 模式实际上效果很好。请求是资源的 HTTP 位置,它被传递到控制器,控制器通过模型加载数据,然后将其传递到视图,视图以所需的任何形式(JSON、XML、二进制等)返回数据。或者,您通常可以直接返回结果,具体取决于您使用的框架。
埃里克
This depends on what you mean by SOA. If you are referring to WS-* standards, I would not recommend MVC, as you will need to write a lot of plumbing to get it to work.
If you are looking for something like a REST service, then the MVC pattern actually works quite well. The request is the HTTP location of the resource, which gets passed to the controller, which loads the data via the model, and then passes it to the view which returns it in whatever form is needed (JSON, XML, Binary, etc). Or, you can often return the result directly, depending on what framework you use.
Erick