---
lang: en
title: 'API docs: context.contextview'
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.contextview.html
---

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

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

## ContextView class

`ContextView` 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 `controller` bindings even they are added/removed/updated after the application starts.

`ContextView` is an event emitter that emits the following events: - 'bind': when a binding is added to the view - 'unbind': when a binding is removed from the view - '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

**Signature:**

```typescript
export declare class ContextView<T = unknown> extends EventEmitter implements ContextObserver 
```
**Extends:** EventEmitter

**Implements:** [ContextObserver](./context.contextobserver.md)

## Constructors

<table><thead><tr><th>

Constructor


</th><th>

Modifiers


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[(constructor)(context, filter, comparator, resolutionOptions)](./context.contextview._constructor_.md)


</td><td>


</td><td>

Create a context view


</td></tr>
</tbody></table>

## Properties

<table><thead><tr><th>

Property


</th><th>

Modifiers


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[\_cachedBindings](./context.contextview._cachedbindings.md)


</td><td>

`protected`


</td><td>

Readonly&lt;[Binding](./context.binding.md)<!-- -->&lt;T&gt;&gt;\[\] \| undefined


</td><td>

An array of cached bindings that matches the binding filter


</td></tr>
<tr><td>

[\_cachedValues](./context.contextview._cachedvalues.md)


</td><td>

`protected`


</td><td>

Map&lt;Readonly&lt;[Binding](./context.binding.md)<!-- -->&lt;T&gt;&gt;, T&gt; \| undefined


</td><td>

A map of cached values by binding


</td></tr>
<tr><td>

[bindings](./context.contextview.bindings.md)


</td><td>

`readonly`


</td><td>

Readonly&lt;[Binding](./context.binding.md)<!-- -->&lt;T&gt;&gt;\[\]


</td><td>

Get the list of matched bindings. If they are not cached, it tries to find them from the context.


</td></tr>
<tr><td>

[comparator?](./context.contextview.comparator.md)


</td><td>

`readonly`


</td><td>

[BindingComparator](./context.bindingcomparator.md) \| undefined


</td><td>

_(Optional)_


</td></tr>
<tr><td>

[context](./context.contextview.context.md)


</td><td>

`readonly`


</td><td>

[Context](./context.context.md)


</td><td>


</td></tr>
<tr><td>

[filter](./context.contextview.filter.md)


</td><td>

`readonly`


</td><td>

[BindingFilter](./context.bindingfilter.md)


</td><td>


</td></tr>
</tbody></table>

## Methods

<table><thead><tr><th>

Method


</th><th>

Modifiers


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[asGetter(session)](./context.contextview.asgetter.md)


</td><td>


</td><td>

As a `Getter` function


</td></tr>
<tr><td>

[close()](./context.contextview.close.md)


</td><td>


</td><td>

Stop listening events from the context


</td></tr>
<tr><td>

[findBindings()](./context.contextview.findbindings.md)


</td><td>

`protected`


</td><td>

Find matching bindings and refresh the cache


</td></tr>
<tr><td>

[observe(event, binding, context)](./context.contextview.observe.md)


</td><td>


</td><td>

Listen on `bind` or `unbind` and invalidate the cache


</td></tr>
<tr><td>

[on(eventName, listener)](./context.contextview.on.md)


</td><td>


</td><td>

The "bind" event is emitted when a new binding is added to the view.


</td></tr>
<tr><td>

[on(eventName, listener)](./context.contextview.on_1.md)


</td><td>


</td><td>

The "unbind" event is emitted a new binding is removed from the view.


</td></tr>
<tr><td>

[on(eventName, listener)](./context.contextview.on_2.md)


</td><td>


</td><td>

The "refresh" event is emitted when the view is refreshed as bindings are added/removed.


</td></tr>
<tr><td>

[on(eventName, listener)](./context.contextview.on_3.md)


</td><td>


</td><td>

The "resolve" event is emitted when the cached values are resolved and updated.


</td></tr>
<tr><td>

[on(eventName, listener)](./context.contextview.on_4.md)


</td><td>


</td><td>

The "close" event is emitted when the view is closed (stopped observing context events)


</td></tr>
<tr><td>

[on(event, listener)](./context.contextview.on_5.md)


</td><td>


</td><td>


</td></tr>
<tr><td>

[once(eventName, listener)](./context.contextview.once.md)


</td><td>


</td><td>

The "bind" event is emitted when a new binding is added to the view.


</td></tr>
<tr><td>

[once(eventName, listener)](./context.contextview.once_1.md)


</td><td>


</td><td>

The "unbind" event is emitted a new binding is removed from the view.


</td></tr>
<tr><td>

[once(eventName, listener)](./context.contextview.once_2.md)


</td><td>


</td><td>

The "refresh" event is emitted when the view is refreshed as bindings are added/removed.


</td></tr>
<tr><td>

[once(eventName, listener)](./context.contextview.once_3.md)


</td><td>


</td><td>

The "resolve" event is emitted when the cached values are resolved and updated.


</td></tr>
<tr><td>

[once(eventName, listener)](./context.contextview.once_4.md)


</td><td>


</td><td>

The "close" event is emitted when the view is closed (stopped observing context events)


</td></tr>
<tr><td>

[once(event, listener)](./context.contextview.once_5.md)


</td><td>


</td><td>


</td></tr>
<tr><td>

[open()](./context.contextview.open.md)


</td><td>


</td><td>

Start listening events from the context


</td></tr>
<tr><td>

[refresh()](./context.contextview.refresh.md)


</td><td>


</td><td>

Refresh the view by invalidating its cache


</td></tr>
<tr><td>

[resolve(session)](./context.contextview.resolve.md)


</td><td>


</td><td>

Resolve values for the matching bindings


</td></tr>
<tr><td>

[singleValue(session)](./context.contextview.singlevalue.md)


</td><td>


</td><td>

Get the single value


</td></tr>
<tr><td>

[values(session)](./context.contextview.values.md)


</td><td>


</td><td>

Get the list of resolved values. If they are not cached, it tries to find and resolve them.


</td></tr>
</tbody></table>


