title: new instances of DbContext
body: <p>I have a .net 4 web api with many controllers that all inherit from the same base controller. This base controller has a method that gets the database connection string and uses it to instantiate a new instance of DbContext. The DbContext is then passed to 10+ repositories which all use that instance of DBContext.</p>
  
  <p>The base controller is doing the following:</p>
  
  <pre><code>public IRepository Repository { get; set; }
  
  public BaseController(IRepository repository)
   {
      this.Repository = repository;
   }
  
  protected override void Initialize(HttpControllerContext controllerContext)
   {
         base.Initialize(controllerContext);
  
         this.Repository = IRepositoryFactory.GetRepository();
  
   }
  
  public static class IRepositoryFactory
  {
      public static IRepository GetRepository()
      {
         // **gets database connectionString**
         var context = new DbContext(connectionString)
  
         // this passes context to all the 10+ repositories using same instance
          return new IDataRepository(context);
      }
  }
  </code></pre>
  
  <p>Is having the base controller instantiate a new instance of DbContext on every api call causing the DbContext to never be reused between calls. In .net core you use the startup class to tell DbContext which database to use, but I don't believe you can do that in .net 4. I am afraid that these new instances of DbContext aren't being used like a Singleton and thus there is no caching going on, causing a lot of unnecessary database hits. Is there a better way to tell DbContext it's connection string and use it without created new instances of DbContext in the BaseController which gets hit on every controller?</p>