title: How to use DbContext in separate class library .net core?
body: <p>I'm trying to access my dbcontext from my .net core 3.1 MVC project in a class library.  Currently I inject my database into the service collection in <code>startup.cs</code></p>
  
  <pre><code>public class AppDbContext : DbContext
  {
      public DbSet&lt;User&gt; Users {get; set;}
      public AppDbContext(DbContextOptions&lt;AppDbContext&gt; options)
          : base(options)
      { }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          // Handles duplicate entry for email in user table
          builder.Entity&lt;User&gt;()
              .HasIndex(u =&gt; u.Email)
              .IsUnique();
      }
  }
  </code></pre>
  
  <p>However, I'm unsure of how to access this AppDbContext in my class library.  I tried accessing it like i would a controller, but obviously it doesn't know about the DI container.</p>
  
  <p><strong>More information:
  <em>This library is used for common requests that are made.  It must always be separate from the main web application and the user should never have to code in this class library.  Therefore, I need to be able to access the dbcontext thats in the main web project from the class library.</em></strong></p>