typedi: question: passing Container to TypeORM useContainer fails
Description
registering Container with typeorm’s useContainer does not work anymore as of the latest release 0.9.0
It throws the following error which is fine for services

Minimal code-snippet showcasing the problem
import { Container } from 'typedi';
import { useContainer } from 'typeorm';
....
useContainer(Container);
Unless I am missing something, this should not fail.
Expected behavior
It used to work fine. This has stopped working as of 0.9.0.
Actual behavior
It should not fail on passing typedi Container to typeorm
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 15
- Comments: 27 (8 by maintainers)
In typeorm-typedi-extensions@0.4.1 has been added custom Container to register with TypeORM. So changing from:
to
helps.
For now I have downgraded to
typedi@0.8.0and it’s working.@danbeneventano here is a sample repository with steps to set it up and run it. it should fail because it cant inject the proper service.
I can confirm decorating all classes that fail with
@Service()fix then issue. Even though it seems unnecessary, it’s good enough for now.Just incase this helps someone. At the time of writing, I was experiencing the same issue while using the latest versions of the following dependencies. I was able to leave TypeOrm at its latest and simply downgraded
typediandtypeorm-typedi-extensionsto the versions listed below. Maybe this will help someone.In my
index.js(entry point) file....useContainer(Container);...Working
You need to add the
@Servicedecorator from TypeDI to every class you ever request from the container viaContainer.get().