Page Contents

Home > @loopback/context > Context > getBinding

Context.getBinding() method

Look up a binding by key in the context and its ancestors. If no matching binding is found and options.optional is not set to true, an error will be thrown.

Signature:

getBinding<ValueType>(key: BindingAddress<ValueType>, options?: {
        optional?: boolean;
    }): Binding<ValueType> | undefined;

Parameters

Parameter Type Description
key BindingAddress<ValueType> Binding key
options { optional?: boolean; } (Optional) Options to control if the binding is optional. If options.optional is set to true, the method will return undefined instead of throwing an error if the binding key is not found.

Returns:

Binding<ValueType> | undefined