title: When should I create a new DbContext()
body: <p>I am currently using a <code>DbContext</code> similar to this:</p>
  <pre><code>namespace Models
  {
      public class ContextDB: DbContext
      {
                
          public DbSet&lt;User&gt; Users { get; set; }
          public DbSet&lt;UserRole&gt; UserRoles { get; set; }
  
          public ContextDB()
          {
              
          }
      }
  }
  </code></pre>
  <p>I am then using the following line at the top of <strong>ALL</strong> my controllers that need access to the database. Im also using it in my UserRepository Class which contains all methods relating to the user (such as getting the active user, checking what roles he has, etc..):</p>
  <pre><code>ContextDB _db = new ContextDB();
  </code></pre>
  <p>Thinking about this, there are occasions when one visitor can have multiple DbContexts active, for instance if it is visiting a controller that uses the UserRepository, which might not be the best of ideas.</p>
  <p>When should I make a new DbContext? Alternatively, should I have one global context that is passed around and reused in all places? Would that cause a performance hit? Suggestions of alternative ways of doing this are also welcome.</p>