---
lang: en
title: 'API docs: context.binding'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/loopback-next/tree/master/packages/context
permalink: /doc/en/lb4/apidocs.context.binding.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)

## Binding class

Binding represents an entry in the `Context`<!-- -->. Each binding has a key and a corresponding value getter.

<b>Signature:</b>

```typescript
export declare class Binding<T = BoundValue> extends EventEmitter 
```
<b>Extends:</b> EventEmitter

## Constructors

|  Constructor | Modifiers | Description |
|  --- | --- | --- |
|  [(constructor)(key, isLocked)](./context.binding._constructor_.md) |  | Constructs a new instance of the <code>Binding</code> class |

## Properties

|  Property | Modifiers | Type | Description |
|  --- | --- | --- | --- |
|  [isLocked](./context.binding.islocked.md) |  | boolean |  |
|  [key](./context.binding.key.md) |  | string | Key of the binding |
|  [providerConstructor](./context.binding.providerconstructor.md) |  | [Constructor](./context.constructor.md)<!-- -->&lt;[Provider](./context.provider.md)<!-- -->&lt;T&gt;&gt; \| undefined | For bindings bound via <code>toProvider()</code>, this property contains the constructor function of the provider class |
|  [scope](./context.binding.scope.md) |  | [BindingScope](./context.bindingscope.md) | Scope of the binding to control how the value is cached/shared |
|  [source](./context.binding.source.md) |  | [BindingSource](./context.bindingsource.md)<!-- -->&lt;T&gt; \| undefined |  |
|  [tagMap](./context.binding.tagmap.md) |  | [TagMap](./context.tagmap.md) | Map for tag name/value pairs |
|  [tagNames](./context.binding.tagnames.md) |  | string\[\] | Get an array of tag names |
|  [type](./context.binding.type.md) |  | [BindingType](./context.bindingtype.md) \| undefined | Type of the binding value getter |
|  [valueConstructor](./context.binding.valueconstructor.md) |  | [Constructor](./context.constructor.md)<!-- -->&lt;T&gt; \| undefined | For bindings bound via <code>toClass()</code>, this property contains the constructor function of the class |

## Methods

|  Method | Modifiers | Description |
|  --- | --- | --- |
|  [apply(templateFns)](./context.binding.apply.md) |  | Apply one or more template functions to set up the binding with scope, tags, and other attributes as a group. |
|  [applyDefaultScope(scope)](./context.binding.applydefaultscope.md) |  | Apply default scope to the binding. It only changes the scope if it's not set yet |
|  [bind(key)](./context.binding.bind.md) | <code>static</code> | A static method to create a binding so that we can do <code>Binding.bind('foo').to('bar');</code> as <code>new Binding('foo').to('bar')</code> is not easy to read. |
|  [configure(key)](./context.binding.configure.md) | <code>static</code> | Create a configuration binding for the given key |
|  [getValue(ctx, session)](./context.binding.getvalue.md) |  | This is an internal function optimized for performance. Users should use <code>@inject(key)</code> or <code>ctx.get(key)</code> instead.<!-- -->Get the value bound to this key. Depending on <code>isSync</code>, this function returns either: - the bound value - a promise of the bound value<!-- -->Consumers wishing to consume sync values directly should use <code>isPromiseLike</code> to check the type of the returned value to decide how to handle it. |
|  [getValue(ctx, options)](./context.binding.getvalue_1.md) |  | Returns a value or promise for this binding in the given context. The resolved value can be <code>undefined</code> if <code>optional</code> is set to <code>true</code> in <code>options</code>. |
|  [inScope(scope)](./context.binding.inscope.md) |  | Set the binding scope |
|  [inspect(options)](./context.binding.inspect.md) |  | Inspect the binding to return a json representation of the binding information |
|  [lock()](./context.binding.lock.md) |  | Lock the binding so that it cannot be rebound |
|  [on(eventName, listener)](./context.binding.on.md) |  | The "changed" event is emitted by methods such as <code>tag</code>, <code>inScope</code>, <code>to</code>, and <code>toClass</code>. |
|  [on(event, listener)](./context.binding.on_1.md) |  |  |
|  [once(eventName, listener)](./context.binding.once.md) |  | The "changed" event is emitted by methods such as <code>tag</code>, <code>inScope</code>, <code>to</code>, and <code>toClass</code>. |
|  [once(event, listener)](./context.binding.once_1.md) |  |  |
|  [refresh(ctx)](./context.binding.refresh.md) |  | Invalidate the binding cache so that its value will be reloaded next time. This is useful to force reloading a cached value when its configuration or dependencies are changed. \*\*WARNING\*\*: The state held in the cached value will be gone. |
|  [tag(tags)](./context.binding.tag.md) |  | Tag the binding with names or name/value objects. A tag has a name and an optional value. If not supplied, the tag name is used as the value. |
|  [to(value)](./context.binding.to.md) |  | Bind the key to a constant value. The value must be already available at binding time, it is not allowed to pass a Promise instance. |
|  [toAlias(keyWithPath)](./context.binding.toalias.md) |  | Bind the key to an alias of another binding |
|  [toClass(ctor)](./context.binding.toclass.md) |  | Bind the key to an instance of the given class. |
|  [toDynamicValue(factory)](./context.binding.todynamicvalue.md) |  | Bind the key to a computed (dynamic) value. |
|  [toInjectable(ctor)](./context.binding.toinjectable.md) |  | Bind to a class optionally decorated with <code>@injectable</code>. Based on the introspection of the class, it calls <code>toClass/toProvider/toDynamicValue</code> internally. The current binding key will be preserved (not being overridden by the key inferred from the class or options).<!-- -->This is similar to [createBindingFromClass()](./context.createbindingfromclass.md) but applies to an existing binding. |
|  [toJSON()](./context.binding.tojson.md) |  | Convert to a plain JSON object |
|  [toProvider(providerClass)](./context.binding.toprovider.md) |  | Bind the key to a value computed by a Provider.<!-- -->\* |
|  [unlock()](./context.binding.unlock.md) |  | Unlock the binding |


