title: How can I EFCore DB Context in an N-Tier architecture with an ASP.NET Core application?
body: <p>I've been trying to follow an asp.net mvc core tutorial online and I noticed that when using entity framework you can enable it in ConfigureServices in the application start up file like so: </p>
  
  <pre class="lang-cs prettyprint-override"><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddDbContext&lt;MyContext&gt;(cfg =&gt; cfg.UseSqlServer());
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
  }
  </code></pre>
  
  <p>but what if I intend to use an n-tier architecture having different projects for the domain and data layers?</p>
  
  <p><a href="https://i.stack.imgur.com/sZ99W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sZ99W.png" alt="enter image description here"></a></p>
  
  <p>So I wouldn't have a reference to EntityFramework or the DBContext in my API layer as these would be separated by a domain layer?</p>
  
  <p>The only solution that comes to mind is to add the Context to a "Common" project but that doesn't feel like the right thing to do? </p>
  
  <p>How would you guys solve this? </p>