---
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) &gt; [@loopback/context](./context.md) &gt; [Binding](./context.binding.md) &gt; [toDynamicValue](./context.binding.todynamicvalue.md)

## Binding.toDynamicValue() method

Bind the key to a computed (dynamic) value.

**Signature:**

```typescript
toDynamicValue(factory: ValueFactory<T> | DynamicValueProviderClass<T>): this;
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td markdown="1">

factory


</td><td markdown="1">

[ValueFactory](./context.valuefactory.md)<!-- -->&lt;T&gt; \| [DynamicValueProviderClass](./context.dynamicvalueproviderclass.md)<!-- -->&lt;T&gt;


</td><td markdown="1">


</td></tr>
</tbody></table>

**Returns:**

this

## Example


```ts
// synchronous
ctx.bind('now').toDynamicValue(() => Date.now());

// asynchronous
ctx.bind('something').toDynamicValue(
 async () => Promise.delay(10).then(doSomething)
);
```


