title: .NET core - read connection string into Entity Framework Core
body: <p>My project structure is pretty standard:</p>
  
  <p><a href="https://i.stack.imgur.com/6ouBO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6ouBO.png" alt="Project structure"></a></p>
  
  <p>within <code>EFData</code>.</p>
  
  <p><code>EFData</code> is an Entity Framework Core class library that isolates all of the database interaction. Database models, and my <code>DBContext</code>. I built it that way so that it's database environment agnostic.</p>
  
  <p>The API project of course has a reference to <code>EFData</code>.</p>
  
  <p>How do I pass the connection string from <code>Startup.cs</code> in <code>API</code> to <code>DBContext.cs</code> in <code>EFData</code>?</p>
  
  <p>I've read multiple articles that reference a set up different than mine where I might expect a <code>Startup.cs</code> in my <code>EFData</code> project. I don't have that.</p>
  
  <p>Within <code>Startup.cs</code>, I do have what I thought was the required line -</p>
  
  <pre><code>services.AddDbContext&lt;DBContext&gt;(options =&gt; options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  </code></pre>
  
  <p>But <code>EFData</code> knows nothing about that connection string.</p>