Lifecycles

Compdi models dependency lifetime explicitly in the macro that defines it.

NeedUseBehavior
One value immediatelycreateSingletonConstructs and exports one shared value.
One value behind an accessordefineSingletonReturns one shared value and supports lazy initialization.
A fresh value per operationcreateTransient or defineTransientReturns a factory that constructs on every call.
A value selected from ambient contextcreateScopedReturns a stable proxy and lifecycle controller.
A value selected by an explicit keydefineScopedReturns a per-context accessor with lifecycle methods.
Full-application cleanupdefineAppTeardownExperimental reverse-order disposal; may be removed.

Use the narrowest lifecycle that represents the ownership of a value. Shared infrastructure such as configuration and database pools is commonly singleton-scoped. Stateful operation objects are usually transient. Request- or tenant-specific state belongs in a scoped dependency.

A practical default

Start with createSingleton for shared infrastructure and createTransient for stateful work. Introduce a scoped dependency only when the same context must reuse a value and different contexts must remain isolated.

Continue with targets, factories, and inference, or go directly to scoped dependencies.