diff --git a/packages/core/docs.json b/packages/core/docs.json index 01c4befdb150..f4634ab5e5c0 100644 --- a/packages/core/docs.json +++ b/packages/core/docs.json @@ -2,7 +2,6 @@ "content": [ "index.ts", "src/application.ts", - "src/booter.ts", "src/component.ts", "src/index.ts", "src/keys.ts", diff --git a/packages/core/src/application.ts b/packages/core/src/application.ts index a4aa77f4cd3f..9c437d45f57f 100644 --- a/packages/core/src/application.ts +++ b/packages/core/src/application.ts @@ -28,10 +28,10 @@ export class Application extends Context { /** * Register a controller class with this application. * - * @param {Function} controllerCtor The controller class - * (constructor function) + * @param controllerCtor {Function} The controller class + * (constructor function). * @param {string=} name Optional controller name, default to the class name - * @returns {Binding} The newly created binding, you can use the reference to + * @return {Binding} The newly created binding, you can use the reference to * further modify the binding, e.g. lock the value to prevent further * modifications. * @@ -43,9 +43,9 @@ export class Application extends Context { */ controller(controllerCtor: ControllerClass, name?: string): Binding { name = name || controllerCtor.name; - return this.bind(`${CoreBindings.CONTROLLERS_PREFIX}.${name}`) + return this.bind(`controllers.${name}`) .toClass(controllerCtor) - .tag(CoreBindings.CONTROLLERS_TAG); + .tag('controller'); } /** diff --git a/packages/core/src/keys.ts b/packages/core/src/keys.ts index 81089f81d562..cdf5d9339d93 100644 --- a/packages/core/src/keys.ts +++ b/packages/core/src/keys.ts @@ -23,10 +23,6 @@ export namespace CoreBindings { */ export const SERVERS = 'servers'; - // Binding Constant prefixes / tags - export const CONTROLLERS_PREFIX = 'controllers'; - export const CONTROLLERS_TAG = 'controller'; - // controller /** * Binding key for the controller class resolved in the current request diff --git a/packages/core/test/unit/application.test.ts b/packages/core/test/unit/application.test.ts index edef7f14e873..5fd3ece0ccc3 100644 --- a/packages/core/test/unit/application.test.ts +++ b/packages/core/test/unit/application.test.ts @@ -4,17 +4,16 @@ // License text available at https://opensource.org/licenses/MIT import {expect} from '@loopback/testlab'; -import {Application, Server, Component} from '../..'; +import {Application, Server, Component} from '../../index'; import {Context, Constructor} from '@loopback/context'; describe('Application', () => { - let app: Application; - - beforeEach(givenApp); - describe('controller binding', () => { + let app: Application; class MyController {} + beforeEach(givenApp); + it('binds a controller', () => { const binding = app.controller(MyController); expect(Array.from(binding.tags)).to.containEql('controller'); @@ -28,14 +27,21 @@ describe('Application', () => { expect(binding.key).to.equal('controllers.my-controller'); expect(findKeysByTag(app, 'controller')).to.containEql(binding.key); }); + + function givenApp() { + app = new Application(); + } }); describe('component binding', () => { + let app: Application; class MyController {} class MyComponent implements Component { controllers = [MyController]; } + beforeEach(givenApp); + it('binds a component', () => { app.component(MyComponent); expect(findKeysByTag(app, 'component')).to.containEql( @@ -49,10 +55,15 @@ describe('Application', () => { 'components.my-component', ); }); + + function givenApp() { + app = new Application(); + } }); describe('server binding', () => { it('defaults to constructor name', async () => { + const app = new Application(); const binding = app.server(FakeServer); expect(Array.from(binding.tags)).to.containEql('server'); const result = await app.getServer(FakeServer.name); @@ -60,6 +71,7 @@ describe('Application', () => { }); it('allows custom name', async () => { + const app = new Application(); const name = 'customName'; app.server(FakeServer, name); const result = await app.getServer(name); @@ -67,6 +79,7 @@ describe('Application', () => { }); it('allows binding of multiple servers as an array', async () => { + const app = new Application(); const bindings = app.servers([FakeServer, AnotherServer]); expect(Array.from(bindings[0].tags)).to.containEql('server'); expect(Array.from(bindings[1].tags)).to.containEql('server'); @@ -79,6 +92,7 @@ describe('Application', () => { describe('start', () => { it('starts all injected servers', async () => { + const app = new Application(); app.component(FakeComponent); await app.start(); @@ -89,6 +103,7 @@ describe('Application', () => { }); it('does not attempt to start poorly named bindings', async () => { + const app = new Application(); app.component(FakeComponent); // The app.start should not attempt to start this binding. @@ -98,10 +113,6 @@ describe('Application', () => { }); }); - function givenApp() { - app = new Application(); - } - function findKeysByTag(ctx: Context, tag: string | RegExp) { return ctx.findByTag(tag).map(binding => binding.key); }