A scoped service lives for one unit of work. In the board-game API, ApplicationDbContext is registered with ASP.NET Core’s service provider so a batch operation can use the same context before it is disposed. section 4.3.4
Configure the scoped database service in Program.cs:
- Register ApplicationDbContext with AddDbContext. section 4.3.4
- Configure SQL Server using the DefaultConnection connection string. section 4.3.4
- Use SaveChanges after the batch operation so EF Core detects and persists the changes. section 4.3.4
- Keep credentials out of committed source by using ignored development settings, environment variables, or Secret Manager. section 4.3.4
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnection"))
);
The registration connects the scoped ApplicationDbContext to SQL Server and retrieves the DefaultConnection value from configuration. section 4.3.4


