liveBook · Manning

Service lifetime

A service lifetime is a dependency-injection rule that determines when service instances are created, how long they are retained, and when they are disposed.

How 2 Manning books explain it

ASP.NET Core in Action, 3e

A service lifetime is the dependency-injection rule that determines how long a registered service instance is retained and when it is disposed.

How it is used
Controls instance creation and reuse when registering application services with ASP.NET Core dependency injection.
How deep it goes
Defines all three lifetimes, illustrates their effect on instance reuse, and addresses manual scoped resolution and disposal.
Examples
Uses email-service registrations and a DataContext shared with a Repository to contrast instance reuse.
What you can do after
Operate/configure it by choosing transient, scoped, or singleton registration and creating a scope for manual scoped resolution.

Read how ASP.NET Core in Action, 3e explains service lifetime →

Pro ASP.NET Core 7, Tenth Edition

A service lifetime is the dependency-injection rule governing when service instances are created and how long they are retained.

How it is used
Configures dependency-injection instance boundaries for middleware, endpoints, handlers, and other components.
How deep it goes
Explains transient and scoped resolution, request scopes, endpoint instantiation, manual scopes, and mixed-lifetime effects.
Examples
Demonstrates GuidService, endpoint handlers, middleware parameters, request-scoped resolution, and timestamping through a chained service.
What you can do after
Apply it via AddTransient, AddScoped, RequestServices, and CreateScope, then verify behavior through endpoint responses.

Read how Pro ASP.NET Core 7, Tenth Edition explains service lifetime →

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.