@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
97 lines (52 loc) • 1.88 kB
Markdown
---
lang: en
title: 'API docs: context.binding.getvalue'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context
permalink: /doc/en/lb4/apidocs.context.binding.getvalue.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/context](./context.md) > [Binding](./context.binding.md) > [getValue](./context.binding.getvalue.md)
## 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:**
```typescript
getValue(ctx: Context, session?: ResolutionSession): ValueOrPromise<T>;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
ctx
</td><td markdown="1">
[Context](./context.context.md)
</td><td markdown="1">
Context for the resolution
</td></tr>
<tr><td markdown="1">
session
</td><td markdown="1">
[ResolutionSession](./context.resolutionsession.md)
</td><td markdown="1">
_(Optional)_ Optional session for binding and dependency resolution
</td></tr>
</tbody></table>
**Returns:**
[ValueOrPromise](./context.valueorpromise.md)<!-- --><T>
## Example
```
const result = binding.getValue(ctx);
if (isPromiseLike(result)) {
result.then(doSomething)
} else {
doSomething(result);
}
```