Page Contents
Home > @loopback/context > Binding > toDynamicValue
Binding.toDynamicValue() method
Bind the key to a computed (dynamic) value.
Signature:
toDynamicValue(factory: ValueFactory<T> | DynamicValueProviderClass<T>): this;
Parameters
Parameter | Type | Description |
---|---|---|
factory | ValueFactory<T> | DynamicValueProviderClass<T> |
Returns:
this
Example
// synchronous
ctx.bind('now').toDynamicValue(() => Date.now());
// asynchronous
ctx.bind('something').toDynamicValue(
async () => Promise.delay(10).then(doSomething)
);