title: Connect multiple Databases to .NET core project via Entity Framework Core
body: <p>I am trying to create a .NET core application that connects to multiple databases, but using one generic repository that contains the logic for all CRUD operations. What is the best way to achieve this? </p>
  
  <pre><code>    public Repository(ApplicationDbContext dbContext)
      {
          _dbContext = dbContext;
          _set = _dbContext.Set&lt;T&gt;();
      }
  </code></pre>
  
  <p>Above is the constructor of my repository. Here, I inject the ApplicationDbContext. I am looking for a way to make this ApplicationDbContext generic, so I only have to need only one repository, in which I can inject different contexts for accessing multiple databases. Essentially I am looking for something like this:</p>
  
  <pre><code>public class Repository_1&lt;T&gt; where T:EntityBase
  {
      public Repository_1(IDbContext dbContext)
      {
  
      }
  }
  </code></pre>
  
  <p>Where I can swap out the dbContext and replace it with another context that connects to another Database.</p>