UNPKG

@loopback/docs

Version:
63 lines (48 loc) 4.42 kB
--- lang: en title: 'API docs: context.binding' keywords: LoopBack 4.0, LoopBack 4 sidebar: lb4_sidebar 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> ``` ## 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) | | <code>boolean</code> | | | [key](./context.binding.key.md) | | <code>string</code> | Key of the binding | | [scope](./context.binding.scope.md) | | <code>BindingScope</code> | Scope of the binding to control how the value is cached/shared | | [tagMap](./context.binding.tagmap.md) | | <code>TagMap</code> | Map for tag name/value pairs | | [tagNames](./context.binding.tagnames.md) | | <code>string[]</code> | Get an array of tag names | | [type](./context.binding.type.md) | | <code>BindingType &#124; undefined</code> | Type of the binding value getter | | [valueConstructor](./context.binding.valueconstructor.md) | | <code>Constructor&lt;T&gt; &#124; undefined</code> | For bindings bound via toClass, this property contains the constructor function | ## 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 | | [lock()](./context.binding.lock.md) | | Lock the binding so that it cannot be rebound | | [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(factoryFn)](./context.binding.todynamicvalue.md) | | Bind the key to a computed (dynamic) value. | | [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 |