DTOS 作为 InputModel/ViewModel 适合分层架构的位置 [英] Where does DTOS as InputModel / ViewModel Fit in Layered Archicture

查看:24
本文介绍了DTOS 作为 InputModel/ViewModel 适合分层架构的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解 InputModel 和 ViewModels 在 4 层架构中的位置.

I'm trying to understand where does InputModel and ViewModels fit at the 4 Layer Architecture.

介绍 |应用 |域 |基础设施

Presentation | Application | Domain | Infrastructure

鉴于应用层负责在表示层和领域层之间交换数据,我认为它们必须存在于这一层中,以及将其转换回领域实体的适配器,反之亦然.

Given that the Application Layer takes care about exchange data beteween Presentation Layer and Domain Layer, I supposed that, they must live inside this layer, as well the adapter to convert It back to Domain Entity and vice versa.

输入模型,也称为命令,在 ASP.NET MVC 中它们可以与视图模型重合.

InputModels, also know as Commands, in ASP.NET MVC they can coincide with ViewModels.

演示文稿中的 ViewModel 对我来说毫无意义.从应用程序层,我应该将 ViewModels 返回到 Presentation 并接收 ViewModels 以将其映射回域实体.如果我在 Presentation 中有 ViewModels,并且 Presentation 是指应用层,我就会有一个循环引用.

Makes no sense to me ViewModels inside the Presentation. From the Application Layer I should return ViewModels to the Presentation and receive ViewModels to Mapp It back to Domain Entity. If I have ViewModels inside the Presentation, and the presentations refers to Application Layer, I will have a loop reference.

此外,例如,如果我在 ASP.NET MVC 中构建了一个 Presentation 并且我有必要为 Windows 应用程序更改它,我将失去这个适合我的必需品的 ViewModel,这太可惜了,因为我已经内置了改变演示技术的一切.

And also, for example, If I have a Presentation build into ASP.NET MVC and I have the necessity to change It for Windows Application I will lost this ViewModels that fit on my requisites, what is a shame, given that I already have everything built in to change the presentation Technology.

我正在阅读来自 Dino Esposito 和 Andrea Saltarello 的书,Microsoft .NET: Architecting for the Enterprise.他们没有过多谈论应用层,只是说,这一层应该编排域服务和存储库以完成用户案例,并在演示文稿中隐藏域.

I'm reading the book From Dino Esposito and Andrea Saltarello, Microsoft .NET: Architecting for the Enterprise. They don't talk too much about the Application Layer, only say that, this one should Orchestrate Domain Services and Repositories to fullfill User Cases, and to hide Domain from the Presentation.

这样对吗?我应该把这个 DTO 放在应用层中吗?如果没有,它们在 Lasangna 上的哪个位置合适?

Is this right? Should I put this DTOs inside the Application Layer? If not, Where does they fit on the Lasangna?

推荐答案

DTO 应该定义在依赖食物链中两层中较高的那一层,以避免循环引用.这意味着 Onion/六边形架构中的应用层,因为依赖指向内——表示引用应用程序.我不知道其他分层架构风格.或者,您可以将 DTO 放置在它们自己的单独层中,该层将被其他两个引用并位于它们之上.

DTOs should be defined in whichever of the two layers is higher in the dependency food chain, to avoid circular references. This would mean the Application layer in an Onion / hexagonal architecture, because dependencies point inward -- Presentation references Application. I don't know about other layered architecture styles. Alternatively, you could place DTO's in their own separate layer which would be referenced by the two others and stand above them.

这篇关于DTOS 作为 InputModel/ViewModel 适合分层架构的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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