Page Contents

Home > @loopback/context > inject > binding

inject.binding variable

Inject the binding object for the given key. This is useful if a binding needs to be set up beyond just a constant value allowed by @inject.setter. The injected binding is found or created based on the metadata.bindingCreation option. See BindingCreationPolicy for more details.


binding: (bindingKey?: string | BindingKey<unknown>, metadata?: InjectBindingMetadata) => (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void


class MyAuthAction {
  @inject.binding('current-user', {
    bindingCreation: BindingCreationPolicy.ALWAYS_CREATE,
  private userBinding: Binding<UserProfile>;

  async authenticate() {
    this.userBinding.toDynamicValue(() => {...});