@loopback/docs
Version:
Documentation for LoopBack 4
32 lines (21 loc) • 3.14 kB
Markdown
---
lang: en
title: 'API docs: context.bindingscope'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.context.bindingscope.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/context](./context.md) > [BindingScope](./context.bindingscope.md)
## BindingScope enum
Scope for binding values
<b>Signature:</b>
```typescript
export declare enum BindingScope
```
## Enumeration Members
| Member | Value | Description |
| --- | --- | --- |
| CONTEXT | <code>"Context"</code> | The binding provides a value as a singleton within each local context. The value is calculated only once per context and cached for subsequential uses. Child contexts have their own value and do not share with their ancestors.<!-- -->For example, with the following context hierarchy:<!-- -->- <code>app</code> (with a binding <code>'b1'</code> that produces sequential values 0, 1, ...) - req1 - req2<!-- -->1. <code>0</code> is the resolved value for <code>'b1'</code> within the <code>app</code> afterward - app.get('b1') ==<!-- -->> 0 (always)<!-- -->2. <code>'b1'</code> is resolved in <code>app</code> but not in <code>req1</code>, a new value <code>1</code> is calculated and used for <code>req1</code> afterward - req1.get('b1') ==<!-- -->> 1 (always)<!-- -->3. <code>'b1'</code> is resolved in <code>app</code> but not in <code>req2</code>, a new value <code>2</code> is calculated and used for <code>req2</code> afterward - req2.get('b1') ==<!-- -->> 2 (always) |
| SINGLETON | <code>"Singleton"</code> | The binding provides a value as a singleton within the context hierarchy (the owning context and its descendants). The value is calculated only once for the owning context and cached for subsequential uses. Child contexts share the same value as their ancestors.<!-- -->For example, with the following context hierarchy:<!-- -->- <code>app</code> (with a binding <code>'b1'</code> that produces sequential values 0, 1, ...) - req1 - req2<!-- -->1. <code>0</code> is the singleton for <code>app</code> afterward - app.get('b1') ==<!-- -->> 0 (always)<!-- -->2. <code>'b1'</code> is resolved in <code>app</code>, reuse it for <code>req1</code> - req1.get('b1') ==<!-- -->> 0 (always)<!-- -->3. <code>'b1'</code> is resolved in <code>app</code>, reuse it for <code>req2</code> - req2.get('b1') ==<!-- -->> 0 (always) |
| TRANSIENT | <code>"Transient"</code> | The binding provides a value that is calculated each time. This will be the default scope if not set.<!-- -->For example, with the following context hierarchy:<!-- -->- <code>app</code> (with a binding <code>'b1'</code> that produces sequential values 0, 1, ...) - req1 - req2<!-- -->Now <code>'b1'</code> is resolved to a new value each time for <code>app</code> and its descendants <code>req1</code> and <code>req2</code>: - app.get('b1') ==<!-- -->> 0 - req1.get('b1') ==<!-- -->> 1 - req2.get('b1') ==<!-- -->> 2 - req2.get('b1') ==<!-- -->> 3 - app.get('b1') ==<!-- -->> 4 |