title: Encapsulating DbContext with using() on Entity Framework Core
body: <p>I wanted to try to expose a DbContext instance through a get statement:</p>
  
  <pre><code>public class SomeContext : DbContext
  {
      public SomeContext()
      {
  
      }
  
      public DbSet&lt;SomeModel1&gt; SomeModel1s { get; set; }
      public DbSet&lt;SomeModel2&gt; SomeModel2s { get; set; }
  
     //etc
  }
  
  public class SomeInterfaceImplementation
  {
      SomeContext ContextInstance { get; }
      //etc
  }
  </code></pre>
  
  <p>But instead of using <code>ContextInstance</code> as a singleton, I want to do something so that calling <code>ContextInstance</code> actually does something like:</p>
  
  <pre><code>someVar = ContextInstance.SomeModel1s.Where(x =&gt; x.SomeID == externalID).OrderBy(x =&gt; x.SomeProperty).ToList();
  //becomes the same as
  using (var db = new SomeContext())
  {
    someVar = db.SomeModel1s.Where(x =&gt; x.SomeID == externalID).OrderBy(x =&gt; x.SomeProperty).ToList();
  }
  </code></pre>
  
  <p>basically, I just want to hide the using statement and create and dispose an instance of SomeContext every time ContextInstance is called. Hopefully I make sense. Does anyone have something in mind to do this?</p>