@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
98 lines (54 loc) • 2.3 kB
Markdown
---
lang: en
title: 'API docs: core.extensions.view'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/core
permalink: /doc/en/lb4/apidocs.core.extensions.view.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/core](./core.md) > [extensions](./core.extensions.md) > [view](./core.extensions.view.md)
## extensions.view() function
Inject a `ContextView` for extensions of the extension point. The view can then be listened on events such as `bind`<!-- -->, `unbind`<!-- -->, or `refresh` to react on changes of extensions.
**Signature:**
```typescript
function view(extensionPointName?: string, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
extensionPointName
</td><td markdown="1">
string
</td><td markdown="1">
_(Optional)_ Name of the extension point. If not supplied, we use the `name` tag from the extension point binding or the class name of the extension point class. If a class needs to inject extensions from multiple extension points, use different `extensionPointName` for different types of extensions.
</td></tr>
<tr><td markdown="1">
metadata
</td><td markdown="1">
[InjectionMetadata](./context.injectionmetadata.md)
</td><td markdown="1">
_(Optional)_ Optional injection metadata
</td></tr>
</tbody></table>
**Returns:**
(target: Object, member: string \| undefined, methodDescriptorOrParameterIndex?: number \| TypedPropertyDescriptor<any> \| undefined) => void
## Example
```ts
import {extensionPoint, extensions} from '@loopback/core';
@extensionPoint(GREETER_EXTENSION_POINT_NAME)
export class GreetingService {
constructor(
@extensions.view() // Inject a context view for extensions of the extension point
private greetersView: ContextView<Greeter>,
// ...
) {
// ...
}
```