第一种方法
/\
/ \
V/ \ C <=WCF=> {Business Layer (with business logic) <=> ORM <=> Database}
/ \
--------
M
与第二种方法
/\
/ \
V/ \ M <=WCF=> {Business Layer (with business logic) <=> ORM <=> Database}
/ \
--------
C
主要区别:
- 在第一种方法中,业务对象将有 2 个版本。一种在业务层内加载属性,另一种愚蠢版本则很少有视图特定属性由控制器填充。而在第二种方法中,将有一个具有所有属性的类。
- 第一种方法似乎与表示层更加解耦
在这两种方法中,控制器都是起点。
就我从不同人那里收到的观点来看,这两种方法都是有效的方法,并且可以根据开发偏好进行切换。
请分享想法。
First Appraoch
/\
/ \
V/ \ C <=WCF=> {Business Layer (with business logic) <=> ORM <=> Database}
/ \
--------
M
Second Approach
/\
/ \
V/ \ M <=WCF=> {Business Layer (with business logic) <=> ORM <=> Database}
/ \
--------
C
Main Difference:
- In first approach, business object will have 2 versions. One loaded with properties inside business layer and other dumb version with few View specific properties to be populated by Controller. While in second appraoch, there will be one class with all properties.
- First approach seem a bit more decoupled from presentation layer
In both approach, Controller would be starting point.
As far from views I've recevied from different people, both are valid approaches and can be toggled as per development preference.
Please share thoughts.
发布评论
评论(3)
我们在 ASP.NET MVC 应用程序中使用下一种方法:
View <- ViewModel <- Controller <-BusinessObject <- Db
您可以从 专业 ASP.NET 设计模式
We are using next approach in asp.net mvc applications:
View <- ViewModel <- Controller <-BusinessObject <- Db
You can get more details about this approach from Professional ASP.NET Design Patterns
第一个。 ViewModel(在三元组中称为“M”)不应该知道视图或业务层中的任何内容。
真正的MVC定义:
微软添加了ViewModel以使分离更加清晰。对于初学者来说,视图不应依赖于您的域模型。而且它不应该包含逻辑。
我在这里列出了使用视图模型的主要原因:http://blog.gauffin.org/2011/07/ Three-reasons-to-why-you-should-use-view-models/
The first one. ViewModels (as you refer as "M" in your triad) should not know of anything in the View or in your business layer.
The real MVC definition:
Microsoft added the ViewModel to make the separation more clear. For starters, the view shouln't be dependent of your domain models. And it should not contain logic.
I've listed the main reasons to use view models here: http://blog.gauffin.org/2011/07/three-reasons-to-why-you-should-use-view-models/
恕我直言,业务逻辑属于模型。控制器不应该知道也不关心为什么你想要在视图中显示某些内容。
事实上,我认为这是一个最适合这里工作的问题,而不仅仅是绝对的“最佳”。
imho Business logic belongs to Models. Controllers shouldn't know nor care about why you want something displayed in your Views.
In fact, i think it's a matter of what's best for the job here, more than an absolute "best".