@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
48 lines (31 loc) • 1.23 kB
Markdown
---
lang: en
title: 'API docs: context.binding.todynamicvalue'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context
permalink: /doc/en/lb4/apidocs.context.binding.todynamicvalue.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/context](./context.md) > [Binding](./context.binding.md) > [toDynamicValue](./context.binding.todynamicvalue.md)
## Binding.toDynamicValue() method
Bind the key to a computed (dynamic) value.
<b>Signature:</b>
```typescript
toDynamicValue(factory: ValueFactory<T> | DynamicValueProviderClass<T>): this;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| factory | [ValueFactory](./context.valuefactory.md)<!-- --><T> \| [DynamicValueProviderClass](./context.dynamicvalueproviderclass.md)<!-- --><T> | |
<b>Returns:</b>
this
## Example
```ts
// synchronous
ctx.bind('now').toDynamicValue(() => Date.now());
// asynchronous
ctx.bind('something').toDynamicValue(
async () => Promise.delay(10).then(doSomething)
);
```