Skip to content

Interface: FactoryBindingDescriptor<T> ​

Defined in: src/wirestate-core/binding/binding.ts:164

Describes a token-bound value produced by a factory function.

Remarks ​

Use a factory binding when a dependency should be created on first resolution, should read other container bindings while it is created, or should create a fresh value for each resolution with Transient scope. Singleton factories are cached after the first resolution. Factory results are not service instances, so service lifecycle decorators and messaging handlers are not wired for the returned value. Container rejects a factory bound under a class token that declares @OnProvision, @OnDeprovision, or a messaging handler, because it owns no instance to run them on.

Type Parameters ​

Type ParameterDefault typeDescription
TunknownValue returned by the factory.

Properties ​

factory ​

ts
readonly factory: (container: Container) => NoInfer<T>;

Defined in: src/wirestate-core/binding/binding.ts:182

Creates the value for this token.

Parameters ​

ParameterType
containerContainer

Returns ​

NoInfer<T>

Remarks ​

Receives the current container and runs inside the injection context, so both current.get(...) and inject(...) can read other bindings.


scope? ​

ts
readonly optional scope?: "Singleton" | "Transient";

Defined in: src/wirestate-core/binding/binding.ts:191

Lifetime scope for factory results.

Remarks ​

Defaults to Singleton, which calls the factory once and reuses the result. Transient calls the factory on every resolution and does not cache the result.


token ​

ts
readonly token: ServiceToken<T>;

Defined in: src/wirestate-core/binding/binding.ts:173

Token used to resolve the factory result.


type? ​

ts
readonly optional type?: "Factory";

Defined in: src/wirestate-core/binding/binding.ts:168

Binding strategy. Optional when the descriptor has a factory field.