Skip to content

Service lifetime

Julian Finkler edited this page Apr 15, 2025 · 3 revisions

You can specify the lifetime of the service in the annotation.

@Service(
  lifetime: ServiceLifetime.singleton, // default
)
class SingletonService {}

@Service(
  lifetime: ServiceLifetime.transient,
)
class TransientService {}
Lifetime Description
Singleton The instance is stored in the container. You'll always receive the same instance.
Transient Everytime you call resolve or tryResolve you'll receive a fresh instance.

Clone this wiki locally