MCPcopy
hub / github.com/loopbackio/loopback-next / findOrCreateBinding

Method findOrCreateBinding

packages/context/src/context.ts:847–864  ·  view source on GitHub ↗

* Find or create a binding for the given key * @param key - Binding address * @param policy - Binding creation policy

(
    key: BindingAddress<T>,
    policy?: BindingCreationPolicy,
  )

Source from the content-addressed store, hash-verified

845 * @param policy - Binding creation policy
846 */
847 findOrCreateBinding<T>(
848 key: BindingAddress<T>,
849 policy?: BindingCreationPolicy,
850 ) {
851 let binding: Binding<T>;
852 if (policy === BindingCreationPolicy.ALWAYS_CREATE) {
853 binding = this.bind(key);
854 } else if (policy === BindingCreationPolicy.NEVER_CREATE) {
855 binding = this.getBinding(key);
856 } else if (this.isBound(key)) {
857 // CREATE_IF_NOT_BOUND - the key is bound
858 binding = this.getBinding(key);
859 } else {
860 // CREATE_IF_NOT_BOUND - the key is not bound
861 binding = this.bind(key);
862 }
863 return binding;
864 }
865
866 /**
867 * Get the value bound to the given key.

Callers 2

context.unit.tsFile · 0.80

Calls 3

bindMethod · 0.95
getBindingMethod · 0.95
isBoundMethod · 0.95

Tested by

no test coverage detected