singleton
A service lifetime, or design, in which one instance is created and shared for the whole life of the process.
In more detail
In dependency injection it is registered with AddSingleton. Because many requests use it at once, a singleton must be thread-safe and must not hold per-request or per-customer state or a scoped service.
Related terms
- service lifetime — How long the container keeps and reuses an instance of a service: transient, scoped or singleton.
- scope validation — A container check that fails when a singleton depends on a scoped service, a bug called a captive dependency.
- IOptions<T> — The options interface that gives a singleton view of an options class, bound once and never recomputed for the life of the process.
Taught in
- The Dependency Injection Container: Scopes and Lifetimes — Modern .NET Core, C# & Enterprise Microservices
- The Options Pattern: Strongly Typed Configuration — Modern .NET Core, C# & Enterprise Microservices