Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF Migration it works only to transient scope #28

Open
DSBRBrasil opened this issue May 18, 2022 · 0 comments
Open

EF Migration it works only to transient scope #28

DSBRBrasil opened this issue May 18, 2022 · 0 comments

Comments

@DSBRBrasil
Copy link

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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant