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](/doc/en/lb4/apidocs.context.valuefactory.html)<T> \| [DynamicValueProviderClass](/doc/en/lb4/apidocs.context.dynamicvalueproviderclass.html)<T>

Returns:

this

Example

// synchronous
ctx.bind('now').toDynamicValue(() => Date.now());

// asynchronous
ctx.bind('something').toDynamicValue(
 async () => Promise.delay(10).then(doSomething)
);