Skip to content

Function: getBindingScope() ​

ts
function getBindingScope(binding: Binding): "Singleton" | "Transient";

Defined in: src/wirestate-core/binding/binding-lifecycle.ts:68

Resolves the caching scope of a binding.

Parameters ​

ParameterTypeDescription
bindingBindingService class or descriptor to inspect.

Returns ​

"Singleton" | "Transient"

The binding scope, Singleton by default.

Remarks ​

A bare service class binds as a singleton, and value descriptors are always singletons. Factory and instance descriptors may declare a Transient scope and otherwise default to Singleton. Use it instead of reading scope directly, which is optional and absent on both value descriptors and a bare class.

Example ​

typescript
import { BindingScope, BindingType, getBindingScope, Injectable } from "@wirestate/core";

@Injectable()
class UserService {}

getBindingScope(UserService); // "Singleton"
getBindingScope({
  token: "REQUEST_ID",
  type: BindingType.Factory,
  scope: BindingScope.Transient,
  factory: () => crypto.randomUUID(),
}); // "Transient"