---
lang: en
title: 'API docs: context'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.context.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/context](./context.md)

## context package

[@loopback/context](https://github.com/strongloop/loopback-next/tree/master/packages/context)

## Classes

|  Class | Description |
|  --- | --- |
|  [Binding](./context.binding.md) | Binding represents an entry in the <code>Context</code>. Each binding has a key and a corresponding value getter. |
|  [BindingKey](./context.bindingkey.md) |  |
|  [Context](./context.context.md) | Context provides an implementation of Inversion of Control (IoC) container |
|  [ContextView](./context.contextview.md) | <code>ContextView</code> provides a view for a given context chain to maintain a live list of matching bindings and their resolved values within the context hierarchy.<!-- -->This class is the key utility to implement dynamic extensions for extension points. For example, the RestServer can react to <code>controller</code> bindings even they are added/removed/updated after the application starts.<code>ContextView</code> is an event emitter that emits the following events: - 'close': when the view is closed (stopped observing context events) - 'refresh': when the view is refreshed as bindings are added/removed - 'resolve': when the cached values are resolved and updated |
|  [DefaultConfigurationResolver](./context.defaultconfigurationresolver.md) | Resolver for configurations of bindings |
|  [InterceptionHandler](./context.interceptionhandler.md) | A proxy handler that applies interceptors<!-- -->See https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global\_Objects/Proxy |
|  [InvocationContext](./context.invocationcontext.md) | InvocationContext represents the context to invoke interceptors for a method. The context can be used to access metadata about the invocation as well as other dependencies. |
|  [ResolutionSession](./context.resolutionsession.md) | Object to keep states for a session to resolve bindings and their dependencies within a context |

## Enumerations

|  Enumeration | Description |
|  --- | --- |
|  [BindingCreationPolicy](./context.bindingcreationpolicy.md) | Policy to control if a binding should be created for the context |
|  [BindingScope](./context.bindingscope.md) | Scope for binding values |
|  [BindingType](./context.bindingtype.md) | Type of the binding source |

## Functions

|  Function | Description |
|  --- | --- |
|  [asBindingTemplate(scopeAndTags)](./context.asbindingtemplate.md) | Convert binding scope and tags as a template function |
|  [asClassOrProvider(target)](./context.asclassorprovider.md) | A factory function to create a template function to bind the target class as a class or <code>Provider</code>. |
|  [asGlobalInterceptor(group)](./context.asglobalinterceptor.md) | The <code>BindingTemplate</code> function to configure a binding as a global interceptor by tagging it with <code>ContextTags.INTERCEPTOR</code> |
|  [asProvider(target)](./context.asprovider.md) | A factory function to create a template function to bind the target class as a <code>Provider</code>. |
|  [asResolutionOptions(optionsOrSession)](./context.asresolutionoptions.md) | Normalize ResolutionOptionsOrSession to ResolutionOptions |
|  [assertTargetType(injection, expectedType, expectedTypeName)](./context.asserttargettype.md) | Assert the target type inspected from TypeScript for injection to be the expected type. If the types don't match, an error is thrown. |
|  [bind(specs)](./context.bind.md) | Decorate a class with binding configuration |
|  [bindingTemplateFor(cls)](./context.bindingtemplatefor.md) | Get the binding template for a class with binding metadata |
|  [compareBindingsByTag(phaseTagName, orderOfPhases)](./context.comparebindingsbytag.md) | Creates a binding compare function to sort bindings by tagged phase name. |
|  [compareByOrder(a, b, order)](./context.comparebyorder.md) | Compare two values by the predefined order |
|  [config(configPath, metadata)](./context.config.md) | Inject a property from <code>config</code> of the current binding. If no corresponding config value is present, <code>undefined</code> will be injected as the configuration binding is resolved with <code>optional: true</code> by default. |
|  [configBindingKeyFor(key, configPath)](./context.configbindingkeyfor.md) | Create binding key for configuration of the binding |
|  [createBindingFromClass(cls, options)](./context.createbindingfromclass.md) | Create a binding from a class with decorated metadata. The class is attached to the binding as follows: - <code>binding.toClass(cls)</code>: if <code>cls</code> is a plain class such as <code>MyController</code> - <code>binding.toProvider(cls)</code>: it <code>cls</code> is a value provider class with a prototype method <code>value()</code> |
|  [createProxyWithInterceptors(target, context)](./context.createproxywithinterceptors.md) | Create a proxy that applies interceptors for method invocations |
|  [createViewGetter(ctx, bindingFilter, session)](./context.createviewgetter.md) | Create a context view as a getter with the given filter |
|  [createViewGetter(ctx, bindingFilter, bindingComparator, session)](./context.createviewgetter_1.md) | Create a context view as a getter with the given filter and sort matched bindings by the comparator. |
|  [describeInjectedArguments(target, method)](./context.describeinjectedarguments.md) | Return an array of injection objects for parameters |
|  [describeInjectedProperties(target)](./context.describeinjectedproperties.md) | Return a map of injection objects for properties |
|  [filterByKey(keyPattern)](./context.filterbykey.md) | Create a binding filter from key pattern |
|  [filterByTag(tagPattern)](./context.filterbytag.md) | Create a binding filter for the tag pattern |
|  [getBindingMetadata(target)](./context.getbindingmetadata.md) | Get binding metadata for a class |
|  [getDeepProperty(value, path)](./context.getdeepproperty.md) | Get nested properties of an object by path |
|  [globalInterceptor(group, specs)](./context.globalinterceptor.md) | <code>@globalInterceptor</code> decorator to mark the class as a global interceptor |
|  [inject(bindingSelector, metadata, resolve)](./context.inject.md) | A decorator to annotate method arguments for automatic injection by LoopBack IoC container. |
|  [inspectTargetType(injection)](./context.inspecttargettype.md) | Inspect the target type for the injection to find out the corresponding JavaScript type |
|  [instantiateClass(ctor, ctx, session, nonInjectedArgs)](./context.instantiateclass.md) | Create an instance of a class which constructor has arguments decorated with <code>@inject</code>.<!-- -->The function returns a class when all dependencies were resolved synchronously, or a Promise otherwise. |
|  [intercept(interceptorOrKeys)](./context.intercept.md) | Decorator function <code>@intercept</code> for classes/methods to apply interceptors. It can be applied on a class and its public methods. Multiple occurrences of <code>@intercept</code> are allowed on the same target class or method. The decorator takes a list of <code>interceptor</code> functions or binding keys. |
|  [invokeMethod(target, method, ctx, nonInjectedArgs)](./context.invokemethod.md) | Invoke an instance method with dependency injection |
|  [invokeMethodWithInterceptors(context, target, methodName, args)](./context.invokemethodwithinterceptors.md) | Invoke a method with the given context |
|  [isBindingAddress(bindingSelector)](./context.isbindingaddress.md) | Type guard for binding address |
|  [isPromiseLike(value)](./context.ispromiselike.md) | Check whether a value is a Promise-like instance. Recognizes both native promises and third-party promise libraries. |
|  [isProviderClass(cls)](./context.isproviderclass.md) | Check if a class implements <code>Provider</code> interface |
|  [mergeInterceptors(interceptorsFromSpec, existingInterceptors)](./context.mergeinterceptors.md) | Adding interceptors from the spec to the front of existing ones. Duplicate entries are eliminated from the spec side.<!-- -->For example:<!-- -->- \[log\] + \[cache, log\] =<!-- -->&gt; \[cache, log\] - \[log\] + \[log, cache\] =<!-- -->&gt; \[log, cache\] - \[\] + \[cache, log\] =<!-- -->&gt; \[cache, log\] - \[cache, log\] + \[\] =<!-- -->&gt; \[cache, log\] - \[log\] + \[cache\] =<!-- -->&gt; \[log, cache\] |
|  [removeNameAndKeyTags(binding)](./context.removenameandkeytags.md) | A binding template function to delete <code>name</code> and <code>key</code> tags |
|  [resolveInjectedArguments(target, method, ctx, session, nonInjectedArgs)](./context.resolveinjectedarguments.md) | Given a function with arguments decorated with <code>@inject</code>, return the list of arguments resolved using the values bound in <code>ctx</code>.<!-- -->The function returns an argument array when all dependencies were resolved synchronously, or a Promise otherwise. |
|  [resolveInjectedProperties(constructor, ctx, session)](./context.resolveinjectedproperties.md) | Given a class with properties decorated with <code>@inject</code>, return the map of properties resolved using the values bound in <code>ctx</code>.<!-- -->The function returns an argument array when all dependencies were resolved synchronously, or a Promise otherwise. |
|  [resolveList(list, resolver)](./context.resolvelist.md) | Resolve entries of an array into a new array with the same indexes. If one or more entries of the source array are resolved to a promise by the <code>resolver</code> function, this method returns a promise which will be resolved to the new array with fully resolved entries. |
|  [resolveMap(map, resolver)](./context.resolvemap.md) | Resolve entries of an object into a new object with the same keys. If one or more entries of the source object are resolved to a promise by the <code>resolver</code> function, this method returns a promise which will be resolved to the new object with fully resolved entries. |
|  [resolveUntil(source, resolver, evaluator)](./context.resolveuntil.md) | Resolve an iterator of source values into a result until the evaluator returns <code>true</code> |
|  [sortBindingsByPhase(bindings, phaseTagName, orderOfPhases)](./context.sortbindingsbyphase.md) | Sort bindings by phase names denoted by a tag and the predefined order |
|  [transformValueOrPromise(valueOrPromise, transformer)](./context.transformvalueorpromise.md) | Transform a value or promise with a function that produces a new value or promise |
|  [tryWithFinally(action, finalAction)](./context.trywithfinally.md) | Try to run an action that returns a promise or a value |

## Interfaces

|  Interface | Description |
|  --- | --- |
|  [BindingComparator](./context.bindingcomparator.md) | Compare function to sort an array of bindings. It is used by <code>Array.prototype.sort()</code>. |
|  [BindingElement](./context.bindingelement.md) | Wrapper for bindings tracked by resolution sessions |
|  [ConfigurationResolver](./context.configurationresolver.md) | Resolver for configuration of bindings. It's responsible for finding corresponding configuration for a given binding key.<!-- -->By default, <code>undefined</code> is expected if no configuration is provided. The behavior can be overridden by setting <code>optional</code> to <code>false</code> in resolution options. |
|  [ContextObserver](./context.contextobserver.md) | Observers of context bind/unbind events |
|  [InjectBindingMetadata](./context.injectbindingmetadata.md) | Metadata for <code>@inject.binding</code> |
|  [Injection](./context.injection.md) | Descriptor for an injection point |
|  [InjectionElement](./context.injectionelement.md) | Wrapper for injections tracked by resolution sessions |
|  [InjectionMetadata](./context.injectionmetadata.md) | An object to provide metadata for <code>@inject</code> |
|  [Interceptor](./context.interceptor.md) | Interceptor function to intercept method invocations |
|  [Provider](./context.provider.md) | Providers allow developers to compute injected values dynamically, with any dependencies required by the value getter injected automatically from the Context. |
|  [ResolutionOptions](./context.resolutionoptions.md) | Options for binding/dependency resolution |
|  [ResolverFunction](./context.resolverfunction.md) | A function to provide resolution of injected values |
|  [Subscription](./context.subscription.md) | Subscription of context events. It's modeled after https://github.com/tc39/proposal-observable. |

## Namespaces

|  Namespace | Description |
|  --- | --- |
|  [bind](./context.bind.md) |  |
|  [config](./context.config.md) |  |
|  [ContextBindings](./context.contextbindings.md) | Namespace for context bindings |
|  [ContextTags](./context.contexttags.md) | Namespace for context tags |
|  [Getter](./context.getter.md) |  |
|  [inject](./context.inject.md) |  |

## Variables

|  Variable | Description |
|  --- | --- |
|  [BINDING\_METADATA\_KEY](./context.binding_metadata_key.md) | Metadata key for binding metadata |
|  [DEFAULT\_TYPE\_NAMESPACES](./context.default_type_namespaces.md) |  |
|  [GLOBAL\_INTERCEPTOR\_NAMESPACE](./context.global_interceptor_namespace.md) | Default namespace for global interceptors |
|  [INTERCEPT\_CLASS\_KEY](./context.intercept_class_key.md) | Metadata key for method-level interceptors |
|  [INTERCEPT\_METHOD\_KEY](./context.intercept_method_key.md) | Metadata key for method-level interceptors |

## Type Aliases

|  Type Alias | Description |
|  --- | --- |
|  [AsInterceptedFunction](./context.asinterceptedfunction.md) | The intercepted variant of a function to return <code>ValueOrPromise&lt;T&gt;</code>. If <code>T</code> is not a function, the type is <code>T</code>. |
|  [AsValueOrPromise](./context.asvalueorpromise.md) | Create the Promise type for <code>T</code>. If <code>T</code> extends <code>Promise</code>, the type is <code>T</code>, otherwise the type is <code>ValueOrPromise&lt;T&gt;</code>. |
|  [AsyncProxy](./context.asyncproxy.md) | The proxy type for <code>T</code>. The return type for any method of <code>T</code> with original return type <code>R</code> becomes <code>ValueOrPromise&lt;R&gt;</code> if <code>R</code> does not extend <code>Promise</code>. Property types stay untouched. |
|  [BindingAddress](./context.bindingaddress.md) |  |
|  [BindingFilter](./context.bindingfilter.md) | A function that filters bindings. It returns <code>true</code> to select a given binding. |
|  [BindingFromClassOptions](./context.bindingfromclassoptions.md) | Options to customize the binding created from a class |
|  [BindingMetadata](./context.bindingmetadata.md) | Binding metadata from <code>@bind</code> |
|  [BindingScopeAndTags](./context.bindingscopeandtags.md) | An object to configure binding scope and tags |
|  [BindingSelector](./context.bindingselector.md) | Select binding(s) by key or a filter function |
|  [BindingSpec](./context.bindingspec.md) | Specification of parameters for <code>@bind()</code> |
|  [BindingTag](./context.bindingtag.md) | Binding tag can be a simple name or name/value pairs |
|  [BindingTemplate](./context.bindingtemplate.md) | A function as the template to configure bindings |
|  [BoundValue](./context.boundvalue.md) |  |
|  [Constructor](./context.constructor.md) | A class constructor accepting arbitrary arguments. |
|  [ContextEventObserver](./context.contexteventobserver.md) | Context event observer type - An instance of <code>ContextObserver</code> or a function |
|  [ContextEventType](./context.contexteventtype.md) | Context event types. We support <code>bind</code> and <code>unbind</code> for now but keep it open for new types |
|  [ContextObserverFn](./context.contextobserverfn.md) | Listen on <code>bind</code>, <code>unbind</code>, or other events |
|  [Getter](./context.getter.md) | The function injected by <code>@inject.getter(bindingSelector)</code>. It can be used to fetch bound value(s) from the underlying binding(s). The return value will be an array if the <code>bindingSelector</code> is a <code>BindingFilter</code> function. |
|  [InterceptorOrKey](./context.interceptororkey.md) | Interceptor function or binding key that can be used as parameters for <code>@intercept()</code> |
|  [InvocationArgs](./context.invocationargs.md) | Array of arguments for a method invocation |
|  [InvocationResult](./context.invocationresult.md) | Return value for a method invocation |
|  [MapObject](./context.mapobject.md) |  |
|  [Notification](./context.notification.md) | Event data for observer notifications |
|  [ResolutionAction](./context.resolutionaction.md) | A function to be executed with the resolution session |
|  [ResolutionElement](./context.resolutionelement.md) | Binding or injection elements tracked by resolution sessions |
|  [ResolutionOptionsOrSession](./context.resolutionoptionsorsession.md) | Resolution options or session |
|  [Setter](./context.setter.md) | The function injected by <code>@inject.setter(bindingKey)</code>. It sets the underlying binding to a constant value using <code>binding.to(value)</code>. |
|  [TagMap](./context.tagmap.md) |  |
|  [TypeNamespaceMapping](./context.typenamespacemapping.md) | Mapping artifact types to binding key namespaces (prefixes). |
|  [ValueOrPromise](./context.valueorpromise.md) | Representing a value or promise. This type is used to represent results of synchronous/asynchronous resolution of values.<!-- -->Note that we are using PromiseLike instead of native Promise to describe the asynchronous variant. This allows producers of async values to use any Promise implementation (e.g. Bluebird) instead of native Promises provided by JavaScript runtime. |


