title: Net Core: Declare New DbContext with a Variable Type
body: <p>How do I declare DbContextOptionsBuilder, where the DbContext is stored in a variable (in this case real name of dbContext is "OnlineShoppingStore" but stored in the two variables below.</p>
  
  <pre><code>var dbContextType = dbContextAssembly.GetTypes().Where(d =&gt; d.BaseType.Name == "DbContext").First();
  var businessDbContext = Activator.CreateInstance(dbContextType) as DbContext;
  DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();
  
  // Attempting Line Below
  var options = new DbContextOptionsBuilder&lt;dbContextType&gt;().UseInMemoryDatabase(databaseName: "Test").Options;
  </code></pre>
  
  <blockquote>
    <p>Error: dbContextType is a variable but is used like a type.</p>
  </blockquote>
  
  <p><strong>End Goal</strong> is to declare a new DbContext, given the type from the assembly above.</p>
  
  <p>Example:</p>
  
  <pre><code>var onlineStoreContext = new OnlineStoreContext(options)
  </code></pre>