MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / component

Method component

packages/core/src/application.ts:462–486  ·  view source on GitHub ↗

* Add a component to this application and register extensions such as * controllers, providers, and servers from the component. * * @param componentCtor - The component class to add. * @param nameOrOptions - Optional component name or options, default to the * class name * * @ex

(
    componentCtor: Constructor<T>,
    nameOrOptions?: string | BindingFromClassOptions,
  )

Source from the content-addressed store, hash-verified

460 * ```
461 */
462 public component<T extends Component = Component>(
463 componentCtor: Constructor<T>,
464 nameOrOptions?: string | BindingFromClassOptions,
465 ) {
466 this.debug('Adding component: %s', nameOrOptions ?? componentCtor.name);
467 const binding = createBindingFromClass(componentCtor, {
468 namespace: CoreBindings.COMPONENTS,
469 type: CoreTags.COMPONENT,
470 defaultScope: BindingScope.SINGLETON,
471 ...toOptions(nameOrOptions),
472 });
473 // Check if the component is already bound
474 const found = this.registry.get(binding.key);
475 if (found?.valueConstructor === binding.valueConstructor) {
476 return binding;
477 }
478 if (isLifeCycleObserverClass(componentCtor)) {
479 binding.apply(asLifeCycleObserver);
480 }
481 this.add(binding);
482 // Assuming components can be synchronously instantiated
483 const instance = this.getSync<Component>(binding.key);
484 mountComponent(this, instance);
485 return binding;
486 }
487
488 /**
489 * Set application metadata. `@loopback/boot` calls this method to populate

Callers 5

givenLoopBackAppFunction · 0.95
givenAnApplicationFunction · 0.95
givenAServerFunction · 0.95
givenRequestContextFunction · 0.95
givenAnApplicationFunction · 0.95

Calls 9

createBindingFromClassFunction · 0.90
isLifeCycleObserverClassFunction · 0.90
mountComponentFunction · 0.90
applyMethod · 0.80
getSyncMethod · 0.80
toOptionsFunction · 0.70
getMethod · 0.65
addMethod · 0.65
debugMethod · 0.45

Tested by 5

givenLoopBackAppFunction · 0.76
givenAnApplicationFunction · 0.76
givenAServerFunction · 0.76
givenRequestContextFunction · 0.76
givenAnApplicationFunction · 0.76