1
1
import "reflect-metadata" ;
2
2
3
- import { instance as globalContainer , typeInfo } from "./dependency-container" ;
4
- import { InjectionToken , Provider } from "./providers" ;
5
- import { constructor , RegistrationOptions } from "./types" ;
6
3
import { INJECTION_TOKEN_METADATA_KEY , getParamInfo } from "./reflection-helpers" ;
4
+ import { InjectionToken , Provider } from "./providers" ;
5
+ import { RegistrationOptions , constructor } from "./types" ;
6
+ import { instance as globalContainer , typeInfo } from "./dependency-container" ;
7
7
8
8
/**
9
9
* Class decorator factory that allows the class' dependencies to be injected
@@ -12,9 +12,9 @@ import {INJECTION_TOKEN_METADATA_KEY, getParamInfo} from "./reflection-helpers";
12
12
* @return {Function } The class decorator
13
13
*/
14
14
export function injectable < T > ( ) : ( target : constructor < T > ) => void {
15
- return function ( target : constructor < T > ) : void {
16
- typeInfo . set ( target , getParamInfo ( target ) ) ;
17
- } ;
15
+ return function ( target : constructor < T > ) : void {
16
+ typeInfo . set ( target , getParamInfo ( target ) ) ;
17
+ } ;
18
18
}
19
19
20
20
/**
@@ -26,15 +26,15 @@ export function injectable<T>(): (target: constructor<T>) => void {
26
26
* @return {Function } The class decorator
27
27
*/
28
28
export function autoInjectable ( ) : ( target : constructor < any > ) => any {
29
- return function ( target : constructor < any > ) : constructor < any > {
30
- const paramInfo = getParamInfo ( target ) ;
29
+ return function ( target : constructor < any > ) : constructor < any > {
30
+ const paramInfo = getParamInfo ( target ) ;
31
31
32
- return class extends target {
33
- constructor ( ...args : any [ ] ) {
34
- super ( ...args . concat ( paramInfo . slice ( args . length ) . map ( type => globalContainer . resolve ( type ) ) ) ) ;
35
- }
36
- }
37
- }
32
+ return class extends target {
33
+ constructor ( ...args : any [ ] ) {
34
+ super ( ...args . concat ( paramInfo . slice ( args . length ) . map ( type => globalContainer . resolve ( type ) ) ) ) ;
35
+ }
36
+ } ;
37
+ } ;
38
38
}
39
39
40
40
/**
@@ -43,22 +43,22 @@ export function autoInjectable(): (target: constructor<any>) => any {
43
43
* @return {Function } The parameter decorator
44
44
*/
45
45
export function inject ( token : InjectionToken < any > ) : ( target : any , propertyKey : string | symbol , parameterIndex : number ) => any {
46
- return function ( target : any , _propertyKey : string | symbol , parameterIndex : number ) : any {
47
- const injectionTokens = Reflect . getOwnMetadata ( INJECTION_TOKEN_METADATA_KEY , target ) || { } ;
48
- injectionTokens [ parameterIndex ] = token ;
49
- Reflect . defineMetadata ( INJECTION_TOKEN_METADATA_KEY , injectionTokens , target ) ;
50
- } ;
46
+ return function ( target : any , _propertyKey : string | symbol , parameterIndex : number ) : any {
47
+ const injectionTokens = Reflect . getOwnMetadata ( INJECTION_TOKEN_METADATA_KEY , target ) || { } ;
48
+ injectionTokens [ parameterIndex ] = token ;
49
+ Reflect . defineMetadata ( INJECTION_TOKEN_METADATA_KEY , injectionTokens , target ) ;
50
+ } ;
51
51
}
52
52
53
53
/**
54
54
* Class decorator factory that allows constructor dependencies to be registered at runtime.
55
55
*
56
56
* @return {Function } The class decorator
57
57
*/
58
- export function registry ( registrations : ( { token : InjectionToken , options ?: RegistrationOptions } & Provider < any > ) [ ] = [ ] ) : ( target : any ) => any {
59
- return function ( target : any ) : any {
60
- registrations . forEach ( ( { token, options, ...provider } ) => globalContainer . register ( token , < any > provider , options ) ) ;
58
+ export function registry ( registrations : ( { token : InjectionToken , options ?: RegistrationOptions } & Provider < any > ) [ ] = [ ] ) : ( target : any ) => any {
59
+ return function ( target : any ) : any {
60
+ registrations . forEach ( ( { token, options, ...provider } ) => globalContainer . register ( token , < any > provider , options ) ) ;
61
61
62
- return target ;
63
- } ;
62
+ return target ;
63
+ } ;
64
64
}
0 commit comments