liveBook · Manning

Bean scope

A dependency-injection scope is a lifetime boundary within which a service or bean instance is created and reused, with separate instances in different scopes.

How 3 Manning books explain it

ASP.NET Core in Action, 3e

A scoped lifetime reuses one service instance within a dependency-injection scope and creates different instances for different scopes.

How it is used
Shares a dependency across services handling one HTTP request while providing a new instance for another request.
How deep it goes
Explains registration, instance reuse, disposal, captive dependencies, and manual scope creation through a worked request example.
Examples
Compares row counts from an endpoint’s DataContext and a Repository’s injected DataContext across requests.
What you can do after
Operate/configure it with AddScoped, scope validation, and manually disposed scopes outside requests.

Read how ASP.NET Core in Action, 3e explains bean scope →

Pro ASP.NET Core 7, Tenth Edition

A scoped service is a dependency-injection service whose instance is reused within a defined scope, such as one HTTP request scope.

How it is used
Controls sharing of dependency-injection service instances among components handling an ASP.NET Core request.
How deep it goes
Explains registration, request-level reuse, manual scopes, and resolution outside a scope through observable behavior rather than container internals.
Examples
Compares GUIDs from three middleware dependencies across requests and from two filter uses in one request.
What you can do after
Operate/configure scoped ASP.NET Core services with AddScoped and create a scope before resolving them during startup.

Read how Pro ASP.NET Core 7, Tenth Edition explains bean scope →

Building Web APIs with ASP.NET Core

A scoped service is a dependency-injected service instance whose lifetime is limited to a single scope, typically one HTTP request in ASP.NET Core.

How it is used
Registers ApplicationDbContext for one unit of work while processing a batch rename operation.
How deep it goes
Explains scoped registration, SaveChanges timing, change detection, persistence, and disposal before addressing connection-string security.
Examples
Uses ApplicationDbContext in Program.cs with a SQL Server DefaultConnection for the MyBGList API.
What you can do after
Operate/configure ApplicationDbContext as a scoped service and protect its connection string with development settings or environment variables.

Read how Building Web APIs with ASP.NET Core explains bean scope →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.