title: Unit of Work, Entity Framework DBContext Scope
body: <p>I've run into a bit of a problem with EF looking for the best practice for this problem: </p>
  
  <pre><code>public void TestEntityFramework_UOWImplementation()
  {
      using (UnitOfWorkInventory uow = new UnitOfWorkInventory())
      {
          IMaterialRepository repos = new MaterialRepository(uow);
  
          Material mat = GetMaterial("Mikes Material", 1);
  
          mat.CostPrice = 20;
  
          repos.InsertOrUpdate(mat);
  
          uow.Commit();
      }
  }
  
  private Material GetMaterial(string sku, int clientId)
  {
      IMaterialRepository repos = new MaterialRepository(new UnitOfWorkInventory();
  
      return repos.Find(sku, clientId);
  
  }
  </code></pre>
  
  <p>In the TestEntityFramework_UOWImplementation() method, its fine, i call create a scope for my unit of work.. and create a repository inside it.</p>
  
  <p>But when i want to getMaterials() as below..  I have no access to the unit of work or the repository, unless i actually pass it as a parameter!  This is clearly not particularly nice.    </p>
  
  <p>How do people get around this problem??</p>
  
  <p>Thanks in advance!</p>
  
  <p>Neil</p>