Page Contents

Home > @loopback/context > Binding > getValue

Binding.getValue() method

This is an internal function optimized for performance. Users should use @inject(key) or ctx.get(key) instead.

Get the value bound to this key. Depending on isSync, this function returns either: - the bound value - a promise of the bound value

Consumers wishing to consume sync values directly should use isPromiseLike to check the type of the returned value to decide how to handle it.

Signature:

getValue(ctx: Context, session?: ResolutionSession): ValueOrPromise<T>;

Parameters

Parameter Type Description
ctx [Context](/doc/en/lb4/apidocs.context.context.html) Context for the resolution
session [ResolutionSession](/doc/en/lb4/apidocs.context.resolutionsession.html) _(Optional)_ Optional session for binding and dependency resolution

Returns:

ValueOrPromise<T>

Example

const result = binding.getValue(ctx);
if (isPromiseLike(result)) {
  result.then(doSomething)
} else {
  doSomething(result);
}