Skip to content

Commit

Permalink
chore: use keys
Browse files Browse the repository at this point in the history
Keys

Signed-off-by: Yaapa Hage <[email protected]>
  • Loading branch information
Yaapa Hage committed Jun 26, 2020
1 parent d714638 commit 23bb5f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/typeorm/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ export namespace TypeOrmBindings {
export const MANAGER = BindingKey.create<ConnectionManager>(
'services.TypeOrmConnectionManager',
);
export const PREFIX = 'connection';
export const TAG = 'typeOrmConnection';
}
10 changes: 5 additions & 5 deletions packages/typeorm/src/mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function TypeOrmMixin<T extends MixinTarget<Application>>(
// 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,
Expand All @@ -37,9 +37,9 @@ export function TypeOrmMixin<T extends MixinTarget<Application>>(
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);
}

Expand All @@ -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,
Expand Down

0 comments on commit 23bb5f4

Please sign in to comment.