I have my ApplicationContext
as following :-
You can see i am deriving ApplicationContext from ChildContext
(child class) that in the end derives from `IdentityDbContext'.
public class ApplicationContext : ChildContext
{
public ApplicationContext(DbContextOptions<ChildContext> options)
: base(options)
{
}
public DbSet<Class> Class { get; set; }
}
public class ChildContext : IdentityDbContext<IfsUser>, IIFSContext
{
public ChildContext(DbContextOptions<ChildContext> options)
: base(options)
{
}
public virtual DbSet<Student> Students { get; set; }
}
Startup.cs
services.AddDbContext<ApplicationContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("ApplicationDB")));
When i try to get instance
var context = services.GetRequiredService<ApplicationContext>();
I get the following error
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[ChildContext]' while attempting to activate 'ApplicationContext'.
In your context's constructors you dont need to do this anymore
public ApplicationContext(DbContextOptions<ChildContext> options)
: base(options)
{
}
Just do
public ApplicationContext(DbContextOptions options)
: base(options)
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With