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

Method add

packages/context/src/context.ts:231–254  ·  view source on GitHub ↗

* Add a binding to the context. If a locked binding already exists with the * same key, an error will be thrown. * @param binding - The configured binding to be added

(binding: Binding<unknown>)

Source from the content-addressed store, hash-verified

229 * @param binding - The configured binding to be added
230 */
231 add(binding: Binding<unknown>): this {
232 const key = binding.key;
233 this.debug('[%s] Adding binding: %s', key);
234 let existingBinding: Binding | undefined;
235 const keyExists = this.registry.has(key);
236 if (keyExists) {
237 existingBinding = this.registry.get(key);
238 const bindingIsLocked = existingBinding?.isLocked;
239 if (bindingIsLocked)
240 throw new Error(`Cannot rebind key "${key}" to a locked binding`);
241 }
242 this.registry.set(key, binding);
243 if (existingBinding !== binding) {
244 if (existingBinding != null) {
245 this.emitEvent('unbind', {
246 binding: existingBinding,
247 context: this,
248 type: 'unbind',
249 });
250 }
251 this.emitEvent('bind', {binding, context: this, type: 'bind'});
252 }
253 return this;
254 }
255
256 /**
257 * Create a corresponding binding for configuration of the target bound by

Callers 7

bindMethod · 0.95
configureMethod · 0.95
givenResolutionErrorFunction · 0.95
assertProviderClassFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95

Calls 4

debugMethod · 0.95
emitEventMethod · 0.95
getMethod · 0.65
setMethod · 0.65

Tested by 2

givenResolutionErrorFunction · 0.76
assertProviderClassFunction · 0.76