MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / Binding

Class Binding

packages/context/src/binding.ts:348–1083  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346 * corresponding value getter.
347 */
348export class Binding<T = BoundValue> extends EventEmitter {
349 /**
350 * Key of the binding
351 */
352 public readonly key: string;
353
354 /**
355 * Map for tag name/value pairs
356 */
357 public readonly tagMap: TagMap = {};
358
359 private _scope?: BindingScope;
360 /**
361 * Scope of the binding to control how the value is cached/shared
362 */
363 public get scope(): BindingScope {
364 // Default to TRANSIENT if not set
365 return this._scope ?? BindingScope.TRANSIENT;
366 }
367
368 /**
369 * Type of the binding value getter
370 */
371 public get type(): BindingType | undefined {
372 return this._source?.type;
373 }
374
375 private _cache: WeakMap<Context, ValueOrPromise<T>>;
376 private _getValue?: ValueFactory<T>;
377
378 /**
379 * The original source value received from `to`, `toClass`, `toDynamicValue`,
380 * `toProvider`, or `toAlias`.
381 */
382 private _source?: BindingSource<T>;
383
384 public get source() {
385 return this._source;
386 }
387
388 /**
389 * For bindings bound via `toClass()`, this property contains the constructor
390 * function of the class
391 */
392 public get valueConstructor(): Constructor<T> | undefined {
393 return this._source?.type === BindingType.CLASS
394 ? this._source?.value
395 : undefined;
396 }
397
398 /**
399 * For bindings bound via `toProvider()`, this property contains the
400 * constructor function of the provider class
401 */
402 public get providerConstructor(): Constructor<Provider<T>> | undefined {
403 return this._source?.type === BindingType.PROVIDER
404 ? this._source?.value
405 : undefined;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected