From 23bb5f45ff0b116138a91514f155ba338cee5639 Mon Sep 17 00:00:00 2001 From: Yaapa Hage Date: Fri, 26 Jun 2020 15:58:39 +0530 Subject: [PATCH] chore: use keys Keys Signed-off-by: Yaapa Hage --- packages/typeorm/src/keys.ts | 2 ++ packages/typeorm/src/mixin.ts | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/typeorm/src/keys.ts b/packages/typeorm/src/keys.ts index 3261befb1412..16e64cd60f8a 100644 --- a/packages/typeorm/src/keys.ts +++ b/packages/typeorm/src/keys.ts @@ -13,4 +13,6 @@ export namespace TypeOrmBindings { export const MANAGER = BindingKey.create( 'services.TypeOrmConnectionManager', ); + export const PREFIX = 'connection'; + export const TAG = 'typeOrmConnection'; } diff --git a/packages/typeorm/src/mixin.ts b/packages/typeorm/src/mixin.ts index d5ab90c8032e..a6b8245c23e0 100644 --- a/packages/typeorm/src/mixin.ts +++ b/packages/typeorm/src/mixin.ts @@ -26,7 +26,7 @@ export function TypeOrmMixin>( // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor(...args: any[]) { super(...args); - this.lifeCycleObserver(StartStop); + this.lifeCycleObserver(TypeOrmStartStop); this.connectionManager = new ConnectionManager(); const binding = this.bind(TypeOrmBindings.MANAGER).to( this.connectionManager, @@ -37,9 +37,9 @@ export function TypeOrmMixin>( connection(connectionConfig: ConnectionOptions) { const connection = this.connectionManager.create(connectionConfig); const name = connection.name; - const binding = this.bind(`connections.${name}`).toDynamicValue(() => - this.connectionManager.get(name), - ); + const binding = this.bind(`${TypeOrmBindings.PREFIX}.${name}`) + .toDynamicValue(() => this.connectionManager.get(name)) + .tag(TypeOrmBindings.TAG); debug('Binding created for connection %s: %j', name, binding); } @@ -58,7 +58,7 @@ export interface ApplicationUsingTypeOrm extends Application { @lifeCycleObserver('datasource', { scope: BindingScope.SINGLETON, }) -export class StartStop implements LifeCycleObserver { +export class TypeOrmStartStop implements LifeCycleObserver { constructor( @inject(TypeOrmBindings.MANAGER) private manager: ConnectionManager,