Function: bindDynamicValue()
ts
function bindDynamicValue<T>(container: Container, entry: InjectableDescriptor): BindWhenOnFluentSyntax<T>;Defined in: src/wirestate-core/bind/bind-dynamic-value.ts:87
Binds a factory-backed value to a token.
Type Parameters
| Type Parameter | Description |
|---|---|
T | Value type. |
Parameters
| Parameter | Type | Description |
|---|---|---|
container | Container | Container to bind into. |
entry | InjectableDescriptor | Descriptor with id, factory or value, and optional scope. |
Returns
Inversify fluent syntax for additional constraints.
Remarks
Use this when the value depends on resolution time. A dynamic value is a vending machine: each resolution can ask the factory for a fresh item, unless you choose singleton scope.
Throws
WirestateError If the descriptor is invalid.
Example
typescript
import { BindingType, ScopeBindingType, bindDynamicValue, createContainer } from "@wirestate/core";
const DATE_NOW = Symbol("DATE_NOW");
const container = createContainer();
bindDynamicValue(container, {
id: DATE_NOW,
bindingType: BindingType.DynamicValue,
scopeBindingType: ScopeBindingType.Transient,
factory: () => new Date(),
});
const now = container.get<Date>(DATE_NOW);