You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys !!! Why doesn't works when singleton or scoped scope are used ? var connectionString = "server=localhost\\sqlexpress;initial catalog=db_sgone_desktop;user id=sa;password=123456;"; services.AddDbContext<ErpDbContext>(opt => opt.UseSqlServer(connectionString)); services.AddSingleton<ErpDbContext>(); services.AddSingleton<IVersaoSistemaRepository, VersaoSistemaRepository>(); services.AddSingleton<IVersionamentoRepository, VersionamentoRepository>();
now, I write the command
add-migration initial, and after update-database
I get the following error: An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Dsbr.Source.Domain.Interfaces.Repositories.INumeroNotaSerieRepository Lifetime: Singleton ImplementationType: Dsbr.Source.Infra.Repositories.NumeroNotaSerieRepository': Cannot consume scoped service 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Dsbr.Source.Infra.EF.Context.ErpDbContext]' from singleton 'Dsbr.Source.Domain.Interfaces.Repositories.INumeroNotaSerieRepository'.)
Therefore, when i change the scope to services.AddTransient it works fine ...
The text was updated successfully, but these errors were encountered:
Hi guys !!! Why doesn't works when singleton or scoped scope are used ?
var connectionString = "server=localhost\\sqlexpress;initial catalog=db_sgone_desktop;user id=sa;password=123456;"; services.AddDbContext<ErpDbContext>(opt => opt.UseSqlServer(connectionString)); services.AddSingleton<ErpDbContext>(); services.AddSingleton<IVersaoSistemaRepository, VersaoSistemaRepository>(); services.AddSingleton<IVersionamentoRepository, VersionamentoRepository>();
now, I write the command
add-migration initial, and after update-database
I get the following error:
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Dsbr.Source.Domain.Interfaces.Repositories.INumeroNotaSerieRepository Lifetime: Singleton ImplementationType: Dsbr.Source.Infra.Repositories.NumeroNotaSerieRepository': Cannot consume scoped service 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Dsbr.Source.Infra.EF.Context.ErpDbContext]' from singleton 'Dsbr.Source.Domain.Interfaces.Repositories.INumeroNotaSerieRepository'.)
Therefore, when i change the scope to services.AddTransient it works fine ...
The text was updated successfully, but these errors were encountered: