title: WCF Message & Data Contract, DTO, domain model, and shared assemblies
body: <p>I have a web client that calls my WCF business service layer, which in turn, calls external WCF services to get the actual data. Initially, I thought I would use DTOs and have separate business entities in the different layers... but I'm finding that the trivial examples advocating for DTOs, to be, well, trivial. I see too much duplicate code and not much benefit.</p>
  
  <p>Consider my Domain:</p>
  
  <p>Example Domain
  I have a single UI screen (Asp.net MVC View) that shows a patient's list of medications, the adverse reactions (between medications), and any clinical conditions (like depression or hypertension) the patient may have. My domain model starts at the top level with:</p>
  
  <pre><code>   MedicationRecord
        List&lt;MedicationProfile&gt; MedicationProfiles
        List&lt;AdverseReactions&gt; Reactions
        List&lt;ClinicalConditions&gt; 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.
  </code></pre>
  
  <p>Further, when making the WCF requests, we have a request/response object, e.g.</p>
  
  <pre><code>   MedicationRecordResponse
        MedicationRecord MedicationRecord
        List&lt;ClientMessage&gt; 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)
  </code></pre>
  
  <p>At this point, my inclination is that the MedicationRecordResponse <em>is</em> my DTO. But in pure DataContracts and DTO and separation of design, am I suppose to do this?</p>
  
  <pre><code>   MedicationRecordResponseDto
        MedicationRecordDto
        List&lt;ClientMessageDto&gt; 
        QueryStatusDto
  
     and that would mean I then need to do
        MedicationProfileDto
        PractitionerDto
        PractitionerTypeDto
        AddressDto
     etc.
  </code></pre>
  
  <p>Because I have show almost all the information on the screen, I am effectively creating 1 DTO for each domain object I have.</p>
  
  <p>My question is -- what would you do? Would you go ahead and create all these DTOs? Or would you just share your domain model in a separate assembly? </p>
  
  <p>Here's some reading from other questions that seemed relevant:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/7176745/wcf-contract-know-the-domain">WCF contract know the domain</a></li>
  <li><a href="https://stackoverflow.com/questions/9480869/alternatives-for-dto-domain-translation-layer-in-soa-wcf">Alternatives for Translation Layer in SOA: WCF</a></li>
  <li><a href="https://stackoverflow.com/questions/3883158/soa-question-exposing-entities">SOA Question: Exposing Entities</a></li>
  </ol>