Skip to content

Interface: FactoryBindingDescriptor<T>

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

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.

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:176

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:185

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:167

Token used to resolve the factory result.


type?

ts
readonly optional type?: "Factory";

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

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