-
Notifications
You must be signed in to change notification settings - Fork 68
Open
Description
"typescript-ioc": "^3.2.2"
export abstract class BaseRepository<T extends BaseModel> {
protected readonly collection: Collection<T>
constructor( @Inject private readonly connectionManager: ConnectionManager )
{
//# Weird -- Why can't I inject this in this constructor, instead?
//const connectionManager = Container.get( ConnectionManager );
//TypeError: Cannot read property 'db' of undefined
this.collection = this.connectionManager.db.collection( this.getCollectionName() )
}
abstract getCollectionName(): string;
}
@Singleton
export class TileRepository extends BaseRepository<Tile> {
getCollectionName()
{
return 'tiles';
}
test()
{
console.log( this.collection.collectionName );
}
}
I've tried several variations of the constructor including a simple @Inject connectionManager: ConnectionManager
to no avail. I've also tried field injection, and that didn't work, but I suspect that information wouldn't be available in the constructor anyhow.
If I add a constructor in TileRepository
and @Inject
the ConnectionManager
, then pass it to super()
it will work, but I don't want to lead that implementation detail.
himalayazest
Metadata
Metadata
Assignees
Labels
No labels