UNPKG

1.56 kBPlain TextView Raw
1// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2// Node module: @loopback/boot
3// This file is licensed under the MIT License.
4// License text available at https://opensource.org/licenses/MIT
5
6import {
7 Application,
8 BindingScope,
9 Component,
10 CoreBindings,
11 inject,
12} from '@loopback/core';
13import {
14 ApplicationMetadataBooter,
15 ControllerBooter,
16 DataSourceBooter,
17 InterceptorProviderBooter,
18 LifeCycleObserverBooter,
19 ModelApiBooter,
20 ModelBooter,
21 RepositoryBooter,
22 ServiceBooter,
23} from './booters';
24import {Bootstrapper} from './bootstrapper';
25import {BootBindings} from './keys';
26
27/**
28 * BootComponent is used to export the default list of Booter's made
29 * available by this module as well as bind the BootStrapper to the app so it
30 * can be used to run the Booters.
31 */
32export class BootComponent implements Component {
33 // Export a list of default booters in the component so they get bound
34 // automatically when this component is mounted.
35 booters = [
36 ApplicationMetadataBooter,
37 ControllerBooter,
38 RepositoryBooter,
39 ServiceBooter,
40 DataSourceBooter,
41 LifeCycleObserverBooter,
42 InterceptorProviderBooter,
43 ModelApiBooter,
44 ModelBooter,
45 ];
46
47 /**
48 *
49 * @param app - Application instance
50 */
51 constructor(@inject(CoreBindings.APPLICATION_INSTANCE) app: Application) {
52 // Bound as a SINGLETON so it can be cached as it has no state
53 app
54 .bind(BootBindings.BOOTSTRAPPER_KEY)
55 .toClass(Bootstrapper)
56 .inScope(BindingScope.SINGLETON);
57 }
58}