Bean scope
A dependency-injection scope defines the lifetime and reuse of a service or bean instance within a bounded context.
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
- Uses scoped services to share request-specific dependencies within an ASP.NET Core request without sharing them across requests.
- How deep it goes
- Explains registration, per-scope reuse, disposal, captive dependencies, and manual scope creation with a worked dependency graph.
- Examples
- Compares a handler and repository sharing a DataContext, and registers an email sender and its dependencies.
- What you can do after
- Apply it via the ASP.NET Core DI container by registering scoped services and creating scopes outside requests.
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 →
Also covered in
- Spring Start Here, Second EditionIn early access (MEAP)
- .NET MAUI in Action
What to know first
- dependency injectionDependency injection is a software design technique in which a component receives its dependencies from outside rather than creating or locating them internally.
- request pipelineA request pipeline is an ordered sequence of processing components through which HTTP requests and their responses pass in a web application.
Related concepts
- AddScopedconfigured by · AddScoped is a .NET dependency-injection registration method that assigns a service a scoped lifetime, creating one instance per lifetime scope.
- application scopeincludes · Application scope is a framework-managed scope in which one component instance is shared throughout an application’s lifetime.
- filterconfigured by · A filter is an MVC component, implemented as an attribute or other mechanism, that can modify or constrain request or response processing.
- OwningComponentBase<T>configured by · OwningComponentBase<T> is a Blazor base component class that scopes a service instance of type T to the lifetime of its owning component.
- prototype scopeincludes · Prototype scope is a Spring bean scope in which the container creates a new bean instance for each request.
Questions about bean scope
What is bean scope?
A dependency-injection scope defines the lifetime and reuse of a service or bean instance within a bounded context.
Which Manning books explain bean scope?
ASP.NET Core in Action, 3e, Pro ASP.NET Core 7, Tenth Edition and Building Web APIs with ASP.NET Core.
What should I know before learning bean scope?
Manning books that teach bean scope usually introduce dependency injection and request pipeline first.
What kinds of bean scope are there?
Kinds of bean scope include application scope and prototype scope.
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.


