在何处放置DTO< ==> WCF服务中的实体翻译器? [英] Where to place DTO <==> Entity translator in WCF service?

查看:53
本文介绍了在何处放置DTO< ==> WCF服务中的实体翻译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设计如下:
我的设计
我的设计http://s15.postimg.org/3zha8rzqh/Design_Idea.png

我将在服务层(左侧服务)中创建一个名为 ProductDTO的类。

I will have a class called 'ProductDTO' in my service layer (the left service).

调用更新产品(ProductDTO)操作合同时,应在业务逻辑层中调用更新产品功能。

When the 'Update Product ( ProductDTO )' operation contract is called - it should call the 'Update Product' function in the Business Logic Layer.

在数据库中(数据访问层 ),有一个名为 Product的实体,由于我使用的是LINQ-To-Entities,所以那里也有一个类

In the database (the 'Data Access Layer') there is an entity called 'Product', and because I use LINQ-To-Entities I will also have a class there called 'Product'.

我的问题是-我在哪里将'ProductDTO'转换为'Product'?

My question is - where do I translate from 'ProductDTO' to 'Product' ?

我应该在服务层中使用 Translate_ProductDTO_To_Product功能吗?
这似乎是最合理的答案,因为那是唯一知道'ProductDTO'是什么的层。

Should I have a 'Translate_ProductDTO_To_Product' function in the service layer ? It seems the most logic answer, because that is the only layer that knows what 'ProductDTO' is.

但这意味着服务层还必须知道产品是什么,因此必须引用数据访问层程序集。

But this means that the service layer will also have to know what 'Product' is, and thus will have to reference the data access layer assemblies.

我认为服务层应该只引用业务逻辑层,而业务逻辑层应该只引用数据访问层,而服务层应该不了解DAL。

I thought that the service layer should only reference the business logic layer, and that the business logic layer should only reference the data access layer, and that the service layer should know nothing about the DAL.

推荐答案

将DTO映射到服务层中的域实体。您的服务层需要了解DTO及其映射到(以及来自)的实体。我强烈建议您使用 AutoMapper 之类的工具进行映射,而不要手工制作。
服务层不应引用您的DA层(或程序集)。稍后,您的BL将需要引用您的DA层以保留实体。
编辑:
您的业务实体可能不应位于DA名称空间下。如果要使用ORM工具生成它们,请确保将任何DDD逻辑放在部分类的另一半。

Map the DTO to your domain entities in your service layer. Your service layer needs to know about DTOs and the entities it is mapping to (and from). I strongly advise you use a tool like AutoMapper to do the mapping rather than hand-crafting. Your service layer should not reference your DA layer (or assembly). Your BL later will need to reference your DA layer to persist the entities. Your business entites probably should not be under a DA namespace. If you are using an ORM tool to generate them, make sure you put any DDD logic in the other half of a partial class.

这篇关于在何处放置DTO< ==> WCF服务中的实体翻译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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