UNPKG

1.92 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2017,2019. All Rights Reserved.
3// Node module: @loopback/core
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.mountComponent = void 0;
8const context_1 = require("@loopback/context");
9/**
10 * Mount a component to an Application.
11 *
12 * @param app - Application
13 * @param component - Component instance
14 */
15function mountComponent(app, component) {
16 if (component.classes) {
17 for (const classKey in component.classes) {
18 const binding = (0, context_1.createBindingFromClass)(component.classes[classKey], {
19 key: classKey,
20 });
21 app.add(binding);
22 }
23 }
24 if (component.providers) {
25 for (const providerKey in component.providers) {
26 const binding = (0, context_1.createBindingFromClass)(component.providers[providerKey], {
27 key: providerKey,
28 });
29 app.add(binding);
30 }
31 }
32 if (component.bindings) {
33 for (const binding of component.bindings) {
34 app.add(binding);
35 }
36 }
37 if (component.controllers) {
38 for (const controllerCtor of component.controllers) {
39 app.controller(controllerCtor);
40 }
41 }
42 if (component.servers) {
43 for (const serverKey in component.servers) {
44 app.server(component.servers[serverKey], serverKey);
45 }
46 }
47 if (component.lifeCycleObservers) {
48 for (const observer of component.lifeCycleObservers) {
49 app.lifeCycleObserver(observer);
50 }
51 }
52 if (component.services) {
53 for (const service of component.services) {
54 app.service(service);
55 }
56 }
57}
58exports.mountComponent = mountComponent;
59//# sourceMappingURL=component.js.map
\No newline at end of file