WCF 消息和数据协定、DTO、域模型和共享程序集

标签 wcf domain-driven-design soa dto datacontract

我有一个 Web 客户端,它调用我的 WCF 业务服务层,后者又调用外部 WCF 服务来获取实际数据。最初,我以为我会使用 DTO 并在不同的层中拥有单独的业务实体……但我发现提倡 DTO 的琐碎示例是微不足道的。我看到太多重复的代码并且没有太大的好处。

考虑我的域:

示例域
我有一个 UI 屏幕(Asp.net MVC View ),显示患者的药物 list 、不良 react (药物之间)以及患者可能患有的任何临床状况(如抑郁症或高血压)。我的域模型从顶层开始:

   MedicationRecord
      List<MedicationProfile> MedicationProfiles
      List<AdverseReactions> Reactions
      List<ClinicalConditions> ClinicalConditions

   MedicationProfile is itself a complex object
      string Name
      decimal Dosage
      Practitioner prescriber 

   Practioner is itself a complex object
      string FirstName
      string LastName
      PractionerType PractionerType
      PractionerId Id
      Address Address    

      etc.

此外,在发出 WCF 请求时,我们有一个请求/响应对象,例如
   MedicationRecordResponse
      MedicationRecord MedicationRecord
      List<ClientMessage> Messages
      QueryStatus Status

   and again, these other objects are complex objects
   (and further, complicates matter is that they exist in a different, common shared namespace)

在这一点上,我的倾向是 MedicationRecordResponse 是我的 DTO。但是在纯 DataContracts 和 DTO 以及设计分离中,我是否应该这样做?
   MedicationRecordResponseDto
      MedicationRecordDto
      List<ClientMessageDto> 
      QueryStatusDto

   and that would mean I then need to do
      MedicationProfileDto
      PractitionerDto
      PractitionerTypeDto
      AddressDto
   etc.

因为我已经在屏幕上显示了几乎所有的信息,所以我有效地为我拥有的每个域对象创建了 1 个 DTO。

我的问题是——你会怎么做?你会继续创建所有这些 DTO 吗?或者你只是在一个单独的程序集中共享你的域模型?

以下是一些似乎相关的其他问题的阅读资料:
  • WCF contract know the domain
  • Alternatives for Translation Layer in SOA: WCF
  • SOA Question: Exposing Entities
  • 最佳答案

    关于WCF 消息和数据协定、DTO、域模型和共享程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11681475/

    相关文章:

    wcf - "Configuring Services with Endpoints"演示对我来说失败 (Microsoft/endpoint.tv/Pluralsight)

    C++ - 使用在 azure 中托管的 C# REST-full WCF 服务

    architecture - 如何在 DDD + CQRS + Event Sourcing 方法中处理业务规则?

    architecture - SOA - 微服务 : Use API REST or SOAP

    wcf - 如何使用一个 WcfFacility 托管多个服务

    c# - 序列化对函数的调用

    repository - DDD : Repository to read and Unit Of Work to write?

    php - 将 Doctrine 与领域驱动设计结合使用

    architecture - SOA 和微服务可以共存吗?

    hadoop - YARN作为SOA框架