I have an EF context that has a signature
public class MyContext : DbContext, IDbContext
{
}
When I add it to services, I use it
services.AddDbContext<MyContext>(op =>
{
op.UseSqlServer(configuration.GetConnectionString("DefaultConnection"));
});
But this causes problems when I enter an IDbContext like this
services.AddScoped(typeof(IDbContext), typeof(MyContext));
Because it duplicates my DbContext, and it should be only one per request.
How can I solve it?
source
share