域VS DTO VS视图模型 - 如何以及何时使用它们? [英] Domain vs DTO vs ViewModel - How and When to use them?

查看:208
本文介绍了域VS DTO VS视图模型 - 如何以及何时使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用域层(DL)/业务(服务)层(BL)/ presentation层(PL),什么是提供实体到presentation层最好的办法一个多层的项目?

In a Multi-layer project with Domain layer (DL)/Business (Service) Layer (BL)/Presentation Layer (PL), what is the best approach to deliver Entities to the Presentation Layer?

DO => Domain Object;
DTO = Domain Transfer Object;
VM => View Model;
V => View;

选项1:

DL => DO => BL => DTO => PL => VM => V

这个选择似乎是最好的做法,但也似乎沉重到十个分量。

This option seems to be the Best Practice but also seems heavy to mantain.

选项2:

DL => DO => BL => DTO => PL => V

这个选择似乎不是很好的做法,但作为DTO是几乎相同的虚拟机,我们可以直接把它传递到视图和它的较少不好受实施和十个分量。

This option seems not very good practice but as DTO are almost identical to the VM, we can pass it directly to the View and it's less painfull to implement and mantain.

这是选项还可靠多种布局,例如,用于移动设备的我可能需要从BL少的信息,所以我需要一个diferent VM为这个特殊的布局?

Is this option also reliable for multiple layouts, for example, for Mobile Devices I may need less information from the BL, so I will need a diferent VM for this particular Layout?

推荐答案

这是确定的DTO传递给视图。如果您需要更改或增强DTO然后创建一个视图模型。一种常见的情况是添加链接。这也是OK的视图模型引用DTO作为一个复杂的属性。

It's OK to pass the DTO to the view. If you need to change or enhance the DTO then create a ViewModel. A common scenario would be to add links. It's also OK for the ViewModel to reference the DTO as a complex property.

这篇关于域VS DTO VS视图模型 - 如何以及何时使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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