Home > @loopback/context > Context
Context class
Context provides an implementation of Inversion of Control (IoC) container
Signature:
export declare class Context extends EventEmitter
Extends: EventEmitter
Constructors
| Constructor | Modifiers | Description |
|---|---|---|
|
Create a new context. |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
|
|
Debugger |
A debug function which can be overridden by subclasses. | |
|
|
(Optional) Parent context | ||
|
|
Configuration resolver | ||
|
|
string |
Name of the context | |
|
|
Map<string, Binding> |
Key to binding map as the internal registry | |
|
Scope for binding resolution | |||
|
|
Manager for observer subscriptions | ||
|
|
ContextTagIndexer |
Indexer for bindings by tag |
Methods
| Method | Modifiers | Description |
|---|---|---|
|
|
Find bindings by tag leveraging indexes | |
|
| ||
|
Add a binding to the context. If a locked binding already exists with the same key, an error will be thrown. | ||
|
Create a binding with the given key in the context. If a locked binding already exists with the same key, an error will be thrown. | ||
|
Close the context: clear observers, stop notifications, and remove event listeners from its parent context. | ||
|
Create a corresponding binding for configuration of the target bound by the given key in the context. For example, | ||
|
Check if a binding exists with the given key in the local context without delegating to the parent context | ||
|
Create a view of the context chain with the given binding filter | ||
|
|
Wrap the debug statement so that it always print out the context name as the prefix | |
|
Emit an | ||
|
A strongly-typed method to emit context events | ||
|
Find bindings using a key pattern or filter function | ||
|
Find bindings using the tag filter. If the filter matches one of the binding tags, the binding is included. | ||
|
Find or create a binding for the given key | ||
|
Get the value bound to the given key, throw an error when no value is bound for the given key. | ||
|
Get the value bound to the given key, optionally return a (deep) property of the bound value. | ||
|
Look up a binding by key in the context and its ancestors. If no matching binding is found, an error will be thrown. | ||
|
Look up a binding by key in the context and its ancestors. If no matching binding is found and | ||
|
Resolve configuration for the binding by key | ||
|
getConfigAsValueOrPromise(key, propertyPath, resolutionOptions) |
Get the value or promise of configuration for a given binding by key | |
|
Resolve configuration synchronously for the binding by key | ||
|
|
Get the debug namespace for the context class. Subclasses can override this method to supply its own namespace. | |
|
Get the owning context for a binding or its key | ||
|
Locate the resolution context for the given binding. Only bindings in the resolution context and its ancestors are visible as dependencies to resolve the given binding | ||
|
Get the context matching the scope | ||
|
Get the synchronous value bound to the given key, optionally return a (deep) property of the bound value. This method throws an error if the bound value requires async computation (returns a promise). You should never rely on sync bindings in production code. | ||
|
Get the synchronous value bound to the given key, optionally return a (deep) property of the bound value. This method throws an error if the bound value requires async computation (returns a promise). You should never rely on sync bindings in production code. | ||
|
Inspect the context and dump out a JSON object representing the context hierarchy | ||
|
Check if a key is bound in the context or its ancestors | ||
|
Check if an observer is subscribed to this context | ||
|
Check if this context is visible (same or ancestor) to the given one | ||
|
The “bind” event is emitted when a new binding is added to the context. The “unbind” event is emitted when an existing binding is removed. | ||
|
The “bind” event is emitted when a new binding is added to the context. The “unbind” event is emitted when an existing binding is removed. | ||
|
|
Set up the configuration resolver if needed | |
|
Add a context event observer to the context | ||
|
Create a plain JSON object for the context | ||
|
Unbind a binding from the context. No parent contexts will be checked. | ||
|
Remove the context event observer from the context |