@@ -5,28 +5,21 @@ import {Container} from "typedi";
5
5
* Allows to inject an EntityManager using typedi's Container.
6
6
*/
7
7
export function OrmEntityManager ( connectionName : string = "default" ) : Function {
8
- return function ( target : Object | Function , propertyName : string , index ?: number ) {
9
-
10
- const getValue = ( ) => {
8
+ return function ( object : Object | Function , propertyName : string , index ?: number ) {
9
+ Container . registerHandler ( { object, index, propertyName, value : ( ) => {
11
10
const connectionManager = Container . get ( ConnectionManager ) ;
12
11
if ( ! connectionManager . has ( connectionName ) )
13
12
throw new Error ( `Cannot get connection "${ connectionName } " from the connection manager. ` +
14
- `Make sure you have created such connection. Also make sure you have called useContainer(Container) ` +
15
- `in your application before you established a connection and importing any entity.` ) ;
13
+ `Make sure you have created such connection. Also make sure you have called useContainer(Container) ` +
14
+ `in your application before you established a connection and importing any entity.` ) ;
16
15
17
16
const connection = connectionManager . get ( connectionName ) ;
18
17
const entityManager = connection . entityManager ;
19
18
if ( ! entityManager )
20
19
throw new Error ( `Entity manager was not found on "${ connectionName } " connection. ` +
21
- `Make sure you correctly setup connection and container usage.` ) ;
20
+ `Make sure you correctly setup connection and container usage.` ) ;
22
21
23
22
return entityManager ;
24
- } ;
25
-
26
- if ( index !== undefined ) {
27
- Container . registerParamHandler ( { type : target as Function , index : index , getValue : getValue } ) ;
28
- } else {
29
- Container . registerPropertyHandler ( { target : target as Function /* todo: looks like typedi wrong type here */ , key : propertyName , getValue : getValue } ) ;
30
- }
23
+ } } ) ;
31
24
} ;
32
25
}
0 commit comments