title: C# EF6 make multiple async calls to one context using Unity - Asp.Net Web Api
body: <p>I get the following error when visiting my SPA site which makes some calls to the API when loaded:</p>
  
  <blockquote>
    <p>A second operation started on this context before a previous
    asynchronous operation completed. Use 'await' to ensure that any
    asynchronous operations have completed before calling another method
    on this context. Any instance members are not guaranteed to be thread
    safe.</p>
  </blockquote>
  
  <p>If I don't use the same context and try to update values I get the following error, see this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/45030136/entity-framework-6-dependency-injection-with-unity-repository-pattern-add">Entity Framework 6 - Dependency Injection with Unity - Repository pattern - Add or Update exception for many to many relationship</a></p>
  
  <blockquote>
    <p>The relationship between the two objects cannot be defined because
    they are attached to different ObjectContext objects.</p>
  </blockquote>
  
  <p>This means that I can't use the answer suggested here to use multiple contexts:</p>
  
  <p><a href="https://stackoverflow.com/a/20635076/3850405">https://stackoverflow.com/a/20635076/3850405</a></p>
  
  <p>UnityConfig.cs:</p>
  
  <pre><code>container.RegisterType&lt;DbContext&gt;(new HierarchicalLifetimeManager());
  container.RegisterType&lt;ISupplierRepository, SupplierRepository&gt;();
  container.RegisterType&lt;IContactRepository, ContactRepository&gt;();
  </code></pre>
  
  <p>How can I solve this?</p>