Page Contents

Home > @loopback/core > extensions > view

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:

function view(extensionPointName?: string, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;

Parameters

Parameter Type Description
extensionPointName string (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.
metadata InjectionMetadata (Optional) Optional injection metadata

Returns:

(target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void

Example

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>,
   // ...
) {
  // ...
}