File tree Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Original file line number Diff line number Diff line change
1
+ import { ContainedType , ContainerInterface , } from 'typeorm' ;
2
+ import { Container , Constructable } from 'typedi' ;
3
+
4
+ /**
5
+ * Class transforming between TypeDI API and the expected API by TypeORM.
6
+ */
7
+ export class TypeDIContainerProvider implements ContainerInterface {
8
+ get < T > ( constructable : ContainedType < T > ) {
9
+ /**
10
+ * TypeDI only resolves values for registered types, so we need to register
11
+ * them before to requesting them from the default container.
12
+ */
13
+ if ( ! Container . has ( constructable as Constructable < T > ) ) {
14
+ Container . set ( { id : constructable , type : constructable as Constructable < T > } ) ;
15
+ }
16
+
17
+ return Container . get ( constructable as Constructable < T > ) ;
18
+ }
19
+ }
Original file line number Diff line number Diff line change 1
- import { Container } from 'typedi' ;
1
+ import { Container as TypeDIContainer } from 'typedi' ;
2
2
import { ConnectionManager } from 'typeorm' ;
3
+ import { TypeDIContainerProvider } from './container-provider.class' ;
4
+
5
+ export * from './decorators/inject-connection.decorator' ;
6
+ export * from './decorators/inject-manager.decorator' ;
7
+ export * from './decorators/inject-repository.decorator' ;
3
8
4
9
/**
5
10
* We need to set imported TypeORM classes before requesting them, otherwise we
6
- * would receive a "ServiceNotFoundError" above TypeDI 0.9.1.
11
+ * would receive a "ServiceNotFoundError" above TypeDI 0.9.1 from the decorators .
7
12
*/
8
- Container . set ( { id : ConnectionManager , type : ConnectionManager } ) ;
13
+ TypeDIContainer . set ( { id : ConnectionManager , type : ConnectionManager } ) ;
9
14
10
- export * from './decorators/inject-connection.decorator' ;
11
- export * from './decorators/inject-manager.decorator' ;
12
- export * from './decorators/inject-repository.decorator' ;
15
+ /**
16
+ * We export the current container implementation what transforms function
17
+ * calls between the TypeORM container format and TypeDI.
18
+ */
19
+ export const Container = new TypeDIContainerProvider ( ) ;
You can’t perform that action at this time.
0 commit comments