业务逻辑层是否在MVC中处理视图模型? [英] Does the Business Logic Layer handle View Models in MVC?

查看:139
本文介绍了业务逻辑层是否在MVC中处理视图模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含4个项目的应用程序

I have an application with 4 projects

  • 演示文稿

BLL

模型

DA

BLL是否应该在表示层之间传递和检索视图模型. (并处理所有映射)

Should the BLL be passing and retrieving View Models to and from the Presentation Layer. (And handle all mapping)

或者应该只处理域模型,并让表示层(控制器)处理所有映射.

Or rather should it only deal with Domain Models and let the Presentation Layer (Controller) handle all mappings.

谢谢

推荐答案

您的开发方法并没有绝对的意义.您可以选择适合自己的情况.但是,当您选择方法时,应该考虑将来的维护和扩展可能性.根据您提供的详细信息,我认为您应该考虑一些问题:

There is nothing absolute about your development approach. you could choose what suits you in any case. But you should consider your future maintenance and extension possibilities when you choose you approach. Based on details you provided, I think you should consider some issues:

  • 用户输入验证:对用户输入的验证不是BLL的一部分.因此,如果您将演示文稿连接到BLL,则会将两者混合使用,这将使您难以管理代码或关注点分离"
  • 在mvc情况下,您始终使用数据注释进行演示.在VM上使用BLL可能使使用它们变得困难.
  • 在表示层上,您需要CSS和Jquery之类的工具.将它们与BLL一起使用,可能会使您的代码非常混乱并且很难 以后再维护.
  • 对于演示文稿中的任何细微更改,您都需要更改BLL,这违反了所有原则!
  • 如果您将BLL与演示文稿混合在一起,将很难为客户提供WebApi之类的服务.
  • 从视图访问BLL,使黑客的生活更轻松!
  • User input verification: verification on user input isn't part of you BLL. So if you connect you presentation to BLL, you will mix both and it makes it hard to manage your code or "separation on concerns"
  • In mvc case you always use data annotation for presentation. Using BLL for VM probably makes it hard to use them.
  • On presentation layer, you need tools like CSS and Jquery. Using them with BLL, probably makes your code very messy and hard to maintain later.
  • For any even minor change on your presentation, you need to change your BLL which is against all principals!.
  • It will be hard to provide services like WebApi for clients, if you intermingled you BLL with presentation.
  • BLL access from views, makes life easier for hackers!.

还有更多!.

这篇关于业务逻辑层是否在MVC中处理视图模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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