title: Multiple Service Layers and Database Transactions
body: <p>I'm just wondering how to best handle transactions across multiple service layers. The service layers use an ORM to store and retrieve from the database. Should the transactions be known and handled within the individual service layers? Or should they be handled by another layer?</p>
  
  <p>For example: I have two service layers for users and clients. I would like to:</p>
  
  <p>1) Create and save a new client<br>
  2) Create and save a new user<br>
  3) Assign that user to the client</p>
  
  <p>All within a single transaction.</p>
  
  <p>A simple example might look like this:</p>
  
  <pre><code>$userManagementService = new UserManagementService;
  $newUserData = array(...);
  $newUser = $userManagementService-&gt;create($newUserData);
  
  $clientManagementService = new ClientManagementService;
  $newClientData = array(...);
  $newClient = $clientManagementService-&gt;create($newClientData);
  
  $userManagementService-&gt;assignUserToClient($newUser, $newClient);
  </code></pre>
  
  <p>Where should transaction logic go?</p>