title: Why does ASP.NET MVC WebAPI template use DbContext as a member variable?
body: <p>If you create a WebAPI/MVC project in say Visual Studio 2013, add Model (and DbContext class), and a Controller for this model as outlined here- </p>
  
  <p><a href="http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-2" rel="nofollow noreferrer">http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-2</a>, </p>
  
  <p>it creates a controller that declares the DbContext as a member variable, which is according to many stackoverflow answers/online arcticles, is a bad idea- like this one </p>
  
  <p><a href="https://stackoverflow.com/a/10588594">https://stackoverflow.com/a/10588594</a> </p>
  
  <p>The controller methods generated by Visual Studio-</p>
  
  <pre><code>// GET: api/Authors
  public IQueryable&lt;Author&gt; GetAuthors()
  {
      return db.Authors;
  }
  </code></pre>
  
  <p>Will not work if you use the recommended per request lifetime -</p>
  
  <pre><code>// GET: api/Authors
      public IQueryable&lt;Author&gt; GetAuthors()
      {
          DbSet&lt;Author&gt; authors = null;
          using(MyContext db = new MyContext) {
               authors = db.Authors;
          }
          return authors;
      }
  </code></pre>
  
  <p>Because the context is out of scope by the time the result is iterated over and you get an object disposed exception.</p>
  
  <p>So, what's the correct way and if it is the "using" per request method, why does the VS template use the member variable method?</p>