I have the following problem.
I have a WebApi Rest in .Net Core where I use EntityFramework Core, I make a request and it works very well, the mess is when I make two requests at the same time, apparently it only supports one at a time, if I do two it generates me the next error attached.
Se ha producido una excepción no controlada por el usuario: CLR/System.InvalidOperationException
An exception of type 'System.InvalidOperationException' occurred in LaboratorioWebApi.dll but was not handled in user code:
'An attempt was made to use the context while it is being configured. A DbContext instance cannot be used inside OnConfiguring since it is still being configured at this point.'
I really do not understand that error nor do I know what to change, I just start with .Net Core and EntityFramework Core, I'm using dependency injection.
I appreciate that you can guide me to know what I should do in those cases.
In my Startup this is the method where I do the injection.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var laboratorio = Configuration.GetValue<string>("DbInfo:Laboratorio");
var soft = Configuration.GetValue<string>("DbInfo:Soft");
services.AddDbContext<LaboratorioContext>(options => options.UseSqlServer(laboratorio));
services.AddDbContext<SofContext>(options => options.UseSqlServer(soft));
// Inyeccion de Dependencias
services.AddSingleton<EquipoRepository>();
services.AddSingleton<TipoEquipoRepository>();
services.AddSingleton<MarcaRepository>();
services.AddSingleton<EmpleadoRepository>();
services.AddSingleton<RangoRepository>();
}
and this is the context
using Microsoft.EntityFrameworkCore;
namespace LaboratorioWebApi.Models
{
public class LaboratorioContext : DbContext
{
public LaboratorioContext(DbContextOptions<LaboratorioContext> options)
: base(options) { }
public DbSet<Equipo> Equipo { get; set; }
public DbSet<EquipoDetalle> EquipoDetalle { get; set; }
public DbSet<Laboratorio> Laboratorio { get; set; }
public DbSet<Marca> Marca { get; set; }
public DbSet<Rango> Rango { get; set; }
public DbSet<Responsable> Responsable { get; set; }
public DbSet<TipoEquipo> TipoEquipo { get; set; }
}
public class SoftContext : DbContext
{
public SoftContext(DbContextOptions<SoftContext> options)
: base(options) { }
public DbSet<Empleado> Empleado { get; set; }
}
}
I hope you can help me. Thank you in advance