Page Contents

Home > @loopback/context > BindingScope

BindingScope enum

Scope for binding values

Signature:

export declare enum BindingScope 

Enumeration Members

Member Value Description
CONTEXT "Context" 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:- app (with a binding 'b1' that produces sequential values 0, 1, …) - req1 - req21. 0 is the resolved value for 'b1' within the app afterward - app.get(‘b1’) ==> 0 (always)2. 'b1' is resolved in app but not in req1, a new value 1 is calculated and used for req1 afterward - req1.get(‘b1’) ==> 1 (always)3. 'b1' is resolved in app but not in req2, a new value 2 is calculated and used for req2 afterward - req2.get(‘b1’) ==> 2 (always)
SINGLETON "Singleton" 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:- app (with a binding 'b1' that produces sequential values 0, 1, …) - req1 - req21. 0 is the singleton for app afterward - app.get(‘b1’) ==> 0 (always)2. 'b1' is resolved in app, reuse it for req1 - req1.get(‘b1’) ==> 0 (always)3. 'b1' is resolved in app, reuse it for req2 - req2.get(‘b1’) ==> 0 (always)
TRANSIENT "Transient" 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:- app (with a binding 'b1' that produces sequential values 0, 1, …) - req1 - req2Now 'b1' is resolved to a new value each time for app and its descendants req1 and req2: - app.get(‘b1’) ==> 0 - req1.get(‘b1’) ==> 1 - req2.get(‘b1’) ==> 2 - req2.get(‘b1’) ==> 3 - app.get(‘b1’) ==> 4