title: Declaring a controller-level instance of the database context
body: <p>In a controller, is there any difference between declaring a database context instance like this:</p>
  <pre><code>public class MyController : Controller
  {
      private readonly MyDatabaseEntities _context = new MyDatabaseEntities();
  
      public ActionResult Index()
      {
          ...
      }
  }
  </code></pre>
  <p>Versus this:</p>
  <pre><code>public class MyController : Controller
  {
      private readonly MyDatabaseEntities _context;
  
      public MyController()
      {
          _context = new MyDatabaseEntities();
      }
  
      public ActionResult Index()
      {
          ...
      }
  }
  </code></pre>
  <p>I'm just beginning to realise that the way I've been handling database context in my ASP.NET apps may not have been correct (or at least ideal) for a while and I'm reading up on it and thinking of how I'm going to start using Dependency Injection, but for starters I was just wondering if I'm even instantiating database contexts in my controllers correctly.</p>
  <p>Incidentally, I'm still working in .NET Framework 4.7.2. Hopefully we'll start working in .NET 5 soon!</p>