I have TypeScript application and I'm using Inversify for IoC.
I have a connection class:
'use strict'; import { injectable } from 'inversify'; import { createConnection, Connection } from "typeorm"; import { Photo, PhotoMetadata, Author, Album } from '../index'; @injectable() class DBConnectionManager { public createPGConnection(): Promise<Connection> { return createConnection({ driver: { type: "postgres", host: "host", port: 5432, username: "username", password: "password", database: "username" }, entities: [ Photo, PhotoMetadata, Author, Album ], autoSchemaSync: true, }); } } export { DBConnectionManager }; After I created my connection I want to bind a connection into my container:
kernel.bind<Connection>('DefaultConnection').toConstantValue(getConnectionManager().get()); and then I want to inject it into another class:
import { injectable, inject } from 'inversify'; import { Connection, FindOptions } from "typeorm"; import { IGenericRepository, ObjectType } from '../index'; @injectable() class GenericRepository<T> implements IGenericRepository<T> { private connection: Connection; private type: ObjectType<T>; constructor( @inject('DefaultConnection') connection: Connection) { this.connection = connection; } So in my container configuration how can I bind DefaultConnection that needs to wait for CreateConnection I can do with async and wait but I'm wonder if there is a cleaner way to achive this in inversify