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 services with a dependency-injection container.
How deep it goes
Explains three lifetime behaviors, contrasts registration methods, and demonstrates scoped resolution outside a request.
Examples
Uses email-service registrations and a random RowCount shared through a repository to illustrate instance reuse.
What you can do after
Apply it via the ASP.NET Core DI container to register services and resolve scoped dependencies outside a request.

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

Questions about service lifetime

What is 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.

Which Manning books explain service lifetime?

ASP.NET Core in Action, 3e and Pro ASP.NET Core 7, Tenth Edition.

What kinds of service lifetime are there?

Kinds of service lifetime include bean scope, Singleton pattern and transient lifetime.

What is service lifetime part of?

Service lifetime is part of service registration. Service registration is the configuration that maps a requested service or interface to the implementation the dependency-injection container should provide.

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.