dotnet / dotnet/AspNetCore.Docs
Documentation about Seeding for Program.cs
- Dominant language
- C#
- Stars
- 13.1k
- Forks
- 24.6k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 97
Description
### Description
Program.cs does not grab a DbContext from DI. That is done in SeedData.
I would change this:
In the previous code, Program.cs has been modified to do the following:
Get a database context instance from the dependency injection (DI) container.
Call the seedData.Initialize method, passing to it the database context instance.
Dispose the context when the seed method completes. The using statement ensures the context is disposed.
to this:
In the previous code, Program.cs has been modified to do the following:
Create a new IServiceScope.
From the new IServiceScope fetch the IServiceProvider
Call the seedData.Initialize method, passing to it the IServiceProvider so that SeedData.Initialize.
Dispose the IServiceScope when the seed method completes. The using statement ensures the IServiceScope is disposed.
### Page URL
https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/sql?view=aspnetcore-8.0&tabs=visual-studio
### Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/tutorials/razor-pages/sql.md
### Document ID
b8c7d824-35ca-68fb-e3be-839ae886657c
### Article author
@wadepickett
Contributor guide
Assessment
This issue has not been assessed yet.