title: Where does my DDD logic belong?
body: <p>I’ve been persuaded by Eric Evans’ book and am integrating DDD into my framework. All basic elements (services, repositories, bounded contexts, etc) have been implemented and now I’m looking for feedback on how to correctly integrate this.</p>
  
  <p>I have some business logic which has to be performed when an entity is created or modified. This example is a very simple one. Most business logic will become much more complex.</p>
  
  <p>This business logic can be split up into the following actions:</p>
  
  <ol>
  <li>Update calculated fields;</li>
  <li>Update a child record inside the aggregate root. When creating the aggregate root this entails creating a default child record. When updating the aggregate root this entails removing the existing child record and creating a new one if a specific field on the aggregate root has changed;</li>
  <li>Propagate start and end date of the aggregate root to the start and end date of the child records inside the aggregate root. These must be kept in sync under certain circumstances;</li>
  <li>Propagate a field of the aggregate root to a different aggregate root.</li>
  </ol>
  
  <p>My first attempt is to put all of this on the aggregate root, but I feel this is not going to work. I have the following problems integrating this logic:</p>
  
  <ul>
  <li>All these actions have to be completed as a single whole and should not be made available as separate actions. This has the result that this is going to be very difficult to test (TDD);</li>
  <li>I am not clear on whether any of these actions can be moved out to a service. The reason for this is that they make no sense outside of the aggregate root, but it would make TDD a lot easier;</li>
  <li>Some logic changes depending on whether a new entity is created or an existing one is modified. Should I put these two branches inside the update logic or should I make two entirely different paths that share the business code that does not differentiate based create/modify.</li>
  </ul>
  
  <p>Any help on the above issues would be greatly appreciated and other feedback in general.</p>