title: How to use UnitOfWork pattern together with IdentityMap pattern?
body: <p>In Martin Fowler's book I read about <code>UnitOfWork</code> and <code>IdentityMap</code>  patterns.</p>
  
  <p>Author mentioned that it is a good idea to put identityMap inside the UnitOfWork. But how to do it ?</p>
  
  <p>As far I understood <code>IdentityMap</code> is bounded by session but author doesn't mentioned it about <code>UnitOfWork</code></p>
  
  <ol>
  <li><p>Is <code>UnitOfWork</code> instance bounded by session?</p></li>
  <li><p>Let's say we have client and order entities.</p>
  
  <pre><code>public clas Client{
  
       List&lt;Order&gt; orders;
      ...
  }
  </code></pre></li>
  </ol>
  
  <p>and we got request to update client information(phone numeber) and add new order:</p>
  
  <p>How many unitOfWork instances do wee need here? for each session? should we have separated instances for client and for order ?</p>
  
  <p>How many IdentityMap instances do we need here ? for each instance ? should we have separated instances for client and for order ?</p>
  
  <p>How many IdentityMap instances do we need for each unitOfWork instance ?</p>
  
  <p>What if we got 2 concurrent requests ?</p>