Skip to main content

Core concepts

Every registration answers three questions: how long its instance lives, when it is ready to use, and who disposes it. The pages in this section give the answers, in the order they build on each other. The coffee shop runs through all of them: the espresso machine is a singleton that warms up once, each order is a scope, and each cup is a transient made fresh.

How they fit together​

ConceptThe question it answersExplained on
LifetimesHow long does an instance live, and how often is it built? You pick [Singleton], [Scoped] or [Transient] per registration.Lifetimes
ScopesWhere do scoped services live, and when do they go away? The root is the outermost scope, and each unit of work opens its own.Scopes
Async initializationWhen is a service ready? A service with asynchronous setup is used only after that setup finished.Async initialization
Lifetime safetyCan a disposable transient leak on a long-lived owner? Strict by default, loose when you want MS.DI semantics.Lifetime safety
DisposalWhich instances does the container dispose, and in which order?Disposal
Owned<T>How do you get a disposable service on demand and decide yourself when it goes away?Owned

What the compiler checks​

The mistakes these concepts guard against stop the build instead of surfacing at run time:

Where to go next​