I am eventually trying to create a library to help me implement Identity into a .NET 6 webapi. I am trying to separate all my code for auth into it's own files so I can eventually replace with my custom library. I want to shied my app from the ApiUser, if I can. I have an issue now where I am getting the error "More than one DbContext was found. Specify which one to use...."
I am not sure how to extend the IdentityDbContext so that I can inject some tables/data of my own without needing to specify which context to use. Technically, my app only uses the one context "ApiDbContext".
ApiAuthIdentityContext.cs - this hides ApiUser and injects seed data
public class ApiAuthDbContext : IdentityDbContext<ApiUser>
{
public ApiAuthDbContext(DbContextOptions options) : base(options)
{
}
}
public class ApiDbContext : ApiAuthDbContext
{
public ApiDbContext(DbContextOptions<ApiDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//seed data for auth
modelBuilder.ApplyConfiguration(new SeedDataRoles());
}
Program.cs
builder.Services.AddDbContext<ApiDbContext>(options =>
options.UseNpgsql(builder.Configuration["DbConnection"])
);
Is there another way to do this where the app only sees the ApiDbContext?