Skip to content

Commit a4778f7

Browse files
committed
feat(core): add constants for namespaces and types
1 parent ae54e45 commit a4778f7

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

packages/core/src/application.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
createBindingFromClass,
1212
} from '@loopback/context';
1313
import {Component, mountComponent} from './component';
14-
import {CoreBindings} from './keys';
14+
import {CoreBindings, CoreTags} from './keys';
1515
import {Server} from './server';
1616

1717
/**
@@ -21,7 +21,7 @@ import {Server} from './server';
2121
*/
2222
export class Application extends Context {
2323
constructor(public options: ApplicationConfig = {}) {
24-
super();
24+
super('application');
2525

2626
// Bind to self to allow injection of application context in other modules.
2727
this.bind(CoreBindings.APPLICATION_INSTANCE).to(this);
@@ -48,8 +48,8 @@ export class Application extends Context {
4848
controller(controllerCtor: ControllerClass, name?: string): Binding {
4949
const binding = createBindingFromClass(controllerCtor, {
5050
name,
51-
namespace: 'controllers',
52-
type: 'controller',
51+
namespace: CoreBindings.CONTROLLERS,
52+
type: CoreTags.CONTROLLER,
5353
defaultScope: BindingScope.TRANSIENT,
5454
});
5555
this.add(binding);
@@ -80,7 +80,7 @@ export class Application extends Context {
8080
const binding = createBindingFromClass(ctor, {
8181
name,
8282
namespace: CoreBindings.SERVERS,
83-
type: 'server',
83+
type: CoreTags.SERVER,
8484
defaultScope: BindingScope.SINGLETON,
8585
});
8686
this.add(binding);
@@ -122,7 +122,7 @@ export class Application extends Context {
122122
* @memberof Application
123123
*/
124124
public async getServer<T extends Server>(
125-
target: Constructor<T> | String,
125+
target: Constructor<T> | string,
126126
): Promise<T> {
127127
let key: string;
128128
// instanceof check not reliable for string.
@@ -196,8 +196,8 @@ export class Application extends Context {
196196
public component(componentCtor: Constructor<Component>, name?: string) {
197197
const binding = createBindingFromClass(componentCtor, {
198198
name,
199-
namespace: 'components',
200-
type: 'component',
199+
namespace: CoreBindings.COMPONENTS,
200+
type: CoreTags.COMPONENT,
201201
defaultScope: BindingScope.SINGLETON,
202202
});
203203
this.add(binding);

packages/core/src/keys.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// License text available at https://opensource.org/licenses/MIT
55

66
import {BindingKey} from '@loopback/context';
7-
import {Application, ControllerClass, ApplicationMetadata} from './application';
7+
import {Application, ApplicationMetadata, ControllerClass} from './application';
88

99
/**
1010
* Namespace for core binding keys
@@ -38,7 +38,15 @@ export namespace CoreBindings {
3838
*/
3939
export const SERVERS = 'servers';
4040

41+
// component
42+
/**
43+
* Binding key for components
44+
*/
45+
export const COMPONENTS = 'components';
46+
4147
// controller
48+
export const CONTROLLERS = 'controllers';
49+
4250
/**
4351
* Binding key for the controller class resolved in the current request
4452
* context
@@ -67,3 +75,20 @@ export namespace CoreBindings {
6775
*/
6876
export const CONTROLLER_CURRENT = BindingKey.create('controller.current');
6977
}
78+
79+
export namespace CoreTags {
80+
/**
81+
* Binding tag for components
82+
*/
83+
export const COMPONENT = 'component';
84+
85+
/**
86+
* Binding tag for servers
87+
*/
88+
export const SERVER = 'server';
89+
90+
/**
91+
* Binding tag for controllers
92+
*/
93+
export const CONTROLLER = 'controller';
94+
}

0 commit comments

Comments
 (0)