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 | Context for the resolution |
session | ResolutionSession | (Optional) Optional session for binding and dependency resolution |
Returns:
Example
const result = binding.getValue(ctx);
if (isPromiseLike(result)) {
result.then(doSomething)
} else {
doSomething(result);
}