liveBook · Manning

AddSingleton

AddSingleton is an ASP.NET Core dependency-injection registration method that reuses one service instance for the application's lifetime.

How 2 Manning books explain it

ASP.NET Core in Action, 3e

AddSingleton is an ASP.NET Core service-registration method that registers a service with singleton lifetime.

How it is used
Registers services with ASP.NET Core's built-in dependency-injection container when one shared instance should satisfy dependencies.
How deep it goes
Defines singleton lifetime and demonstrates type and object registration, but defers detailed lifetime discussion and asynchronous factories.
Examples
Uses MessageFactory and EmailServerSettings to demonstrate type registration and reuse of a supplied configuration object.
What you can do after
Operate/configure ASP.NET Core's DI container by registering a reusable service or preconstructed object with AddSingleton.

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

Pro ASP.NET Core 7, Tenth Edition

AddSingleton is an ASP.NET Core dependency-injection registration method that reuses one service instance for the lifetime of the application.

How it is used
Registers shared services in ASP.NET Core's dependency-injection container for handlers and other components.
How deep it goes
Explains generic registration, handler resolution, first-use creation, and reuse, then contrasts scoped and transient lifecycles.
Examples
Uses IResponseFormatter with HtmlResponseFormatter and IHttpContextAccessor with HttpContextAccessor as registration examples.
What you can do after
Apply it via ASP.NET Core dependency injection to provide one reusable implementation instance wherever its service type is requested.

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

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.