1
1
import { ConnectionManager , Repository , TreeRepository , MongoRepository } from 'typeorm' ;
2
- import { Constructable , Container } from 'typedi' ;
2
+ import { Constructable , Container , ContainerInstance } from 'typedi' ;
3
3
4
4
import { EntityTypeMissingError } from '../errors/EntityTypeMissingError' ;
5
5
import { PropertyTypeMissingError } from '../errors/PropertyTypeMissingError' ;
@@ -8,8 +8,13 @@ import { ParamTypeMissingError } from '../errors/ParamTypeMissingError';
8
8
/**
9
9
* Helper to avoid V8 compilation of anonymous function on each call of decorator.
10
10
*/
11
- function getRepository ( connectionName : string , repositoryType : Function , entityType : Function ) {
12
- const connectionManager = Container . get ( ConnectionManager ) ;
11
+ function getRepository (
12
+ connectionName : string ,
13
+ repositoryType : Function ,
14
+ entityType : Function ,
15
+ containerInstance : ContainerInstance
16
+ ) {
17
+ const connectionManager = containerInstance . get ( ConnectionManager ) ;
13
18
if ( ! connectionManager . has ( connectionName ) ) {
14
19
throw new Error (
15
20
`Cannot get connection "${ connectionName } " from the connection manager. ` +
@@ -159,7 +164,7 @@ export function InjectRepository(
159
164
index,
160
165
object : object as Constructable < unknown > ,
161
166
propertyName,
162
- value : ( ) => getRepository ( connectionName , repositoryType , entityType ! ) ,
167
+ value : containerInstance => getRepository ( connectionName , repositoryType , entityType ! , containerInstance ) ,
163
168
} ) ;
164
169
} ;
165
170
}
0 commit comments