@spinajs/di 2.0.179 → 2.0.181
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/array.d.ts +10 -10
- package/lib/cjs/array.js +13 -13
- package/lib/cjs/binder.d.ts +39 -39
- package/lib/cjs/binder.js +96 -96
- package/lib/cjs/container-cache.d.ts +17 -17
- package/lib/cjs/container-cache.js +63 -63
- package/lib/cjs/container.d.ts +133 -133
- package/lib/cjs/container.js +466 -466
- package/lib/cjs/container.js.map +1 -1
- package/lib/cjs/decorators.d.ts +141 -141
- package/lib/cjs/decorators.js +303 -303
- package/lib/cjs/enums.d.ts +31 -31
- package/lib/cjs/enums.js +35 -35
- package/lib/cjs/enums.js.map +1 -1
- package/lib/cjs/exceptions.d.ts +17 -17
- package/lib/cjs/exceptions.js +25 -25
- package/lib/cjs/helpers.d.ts +35 -35
- package/lib/cjs/helpers.js +86 -86
- package/lib/cjs/index.d.ts +12 -12
- package/lib/cjs/index.js +41 -41
- package/lib/cjs/interfaces.d.ts +172 -172
- package/lib/cjs/interfaces.js +53 -53
- package/lib/cjs/registry.d.ts +14 -14
- package/lib/cjs/registry.js +80 -80
- package/lib/cjs/root.d.ts +108 -108
- package/lib/cjs/root.js +216 -217
- package/lib/cjs/root.js.map +1 -1
- package/lib/cjs/types.d.ts +13 -13
- package/lib/cjs/types.js +2 -2
- package/lib/mjs/array.d.ts +10 -10
- package/lib/mjs/array.js +9 -9
- package/lib/mjs/binder.d.ts +39 -39
- package/lib/mjs/binder.js +92 -92
- package/lib/mjs/container-cache.d.ts +17 -17
- package/lib/mjs/container-cache.js +59 -59
- package/lib/mjs/container.d.ts +133 -133
- package/lib/mjs/container.js +459 -459
- package/lib/mjs/container.js.map +1 -1
- package/lib/mjs/decorators.d.ts +141 -141
- package/lib/mjs/decorators.js +266 -266
- package/lib/mjs/enums.d.ts +31 -31
- package/lib/mjs/enums.js +32 -32
- package/lib/mjs/enums.js.map +1 -1
- package/lib/mjs/exceptions.d.ts +17 -17
- package/lib/mjs/exceptions.js +19 -19
- package/lib/mjs/helpers.d.ts +35 -35
- package/lib/mjs/helpers.js +72 -72
- package/lib/mjs/index.d.ts +12 -12
- package/lib/mjs/index.js +12 -12
- package/lib/mjs/interfaces.d.ts +172 -172
- package/lib/mjs/interfaces.js +45 -45
- package/lib/mjs/registry.d.ts +14 -14
- package/lib/mjs/registry.js +76 -76
- package/lib/mjs/root.d.ts +108 -108
- package/lib/mjs/root.js +159 -159
- package/lib/mjs/types.d.ts +13 -13
- package/lib/mjs/types.js +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +2 -2
package/lib/cjs/container.d.ts
CHANGED
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
import { TypedArray } from './array.js';
|
|
4
|
-
import { IBind, IContainer, IInjectDescriptor, IResolvedInjection, IToInject, AsyncService, ResolvableObject } from './interfaces.js';
|
|
5
|
-
import { Class, Factory } from './types.js';
|
|
6
|
-
import { EventEmitter } from 'events';
|
|
7
|
-
import { Registry } from './registry.js';
|
|
8
|
-
import { ContainerCache } from './container-cache.js';
|
|
9
|
-
/**
|
|
10
|
-
* Dependency injection container implementation
|
|
11
|
-
*/
|
|
12
|
-
export declare class Container extends EventEmitter implements IContainer {
|
|
13
|
-
/**
|
|
14
|
-
* Handles information about what is registered as what
|
|
15
|
-
* eg. that class IConfiguration should be resolved as DatabaseConfiguration etc.
|
|
16
|
-
*/
|
|
17
|
-
private registry;
|
|
18
|
-
/**
|
|
19
|
-
* Singletons cache, objects that should be created only once are stored here.
|
|
20
|
-
*/
|
|
21
|
-
private cache;
|
|
22
|
-
/**
|
|
23
|
-
* Parent container if avaible
|
|
24
|
-
*/
|
|
25
|
-
private parent;
|
|
26
|
-
/**
|
|
27
|
-
* Returns container cache - map object with resolved classes as singletons
|
|
28
|
-
*/
|
|
29
|
-
get Cache(): ContainerCache;
|
|
30
|
-
get Registry(): Registry;
|
|
31
|
-
get Parent(): IContainer;
|
|
32
|
-
constructor(parent?: IContainer);
|
|
33
|
-
/**
|
|
34
|
-
* Clears container registry and cache. shorthand for container.clearCache() && container.clearRegistry()
|
|
35
|
-
*/
|
|
36
|
-
clear(): void;
|
|
37
|
-
dispose(): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* clears container registered types information
|
|
40
|
-
*/
|
|
41
|
-
clearCache(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Clears container resolved types
|
|
44
|
-
*/
|
|
45
|
-
clearRegistry(): void;
|
|
46
|
-
/**
|
|
47
|
-
* Register class/interface to DI.
|
|
48
|
-
* @param type - interface object to register
|
|
49
|
-
* @throws {@link InvalidArgument} if type is null or undefined
|
|
50
|
-
*/
|
|
51
|
-
register<T>(implementation: Class<T> | Factory<T> | ResolvableObject): IBind;
|
|
52
|
-
unregister<T>(implementation: string | Class<T> | Factory<T> | ResolvableObject): void;
|
|
53
|
-
uncache<T>(implementation: string | Class<T> | TypedArray<T>, parent?: boolean): void;
|
|
54
|
-
/**
|
|
55
|
-
* Creates child DI container.
|
|
56
|
-
*
|
|
57
|
-
*/
|
|
58
|
-
child(): IContainer;
|
|
59
|
-
/**
|
|
60
|
-
* Gets already resolved services. Works only for singleton classes.
|
|
61
|
-
*
|
|
62
|
-
* Do not try to get service by factory func, it will always return null.
|
|
63
|
-
* If you somehowe want to cache instances created by factory functions,
|
|
64
|
-
* factory itself should do that somehow and end user should always resolve by
|
|
65
|
-
* assigned type
|
|
66
|
-
*
|
|
67
|
-
* @param serviceName - name of service to get
|
|
68
|
-
* @returns null if no service has been resolved at given name
|
|
69
|
-
*/
|
|
70
|
-
get<T>(service: TypedArray<T>, parent?: boolean): T[];
|
|
71
|
-
get<T>(service: string | Class<T>, parent?: boolean): T;
|
|
72
|
-
hasRegistered<T>(service: Class<T> | string, parent?: boolean): boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Checks if service is already resolved and exists in container cache.
|
|
75
|
-
* NOTE: check is only valid for classes that are singletons.
|
|
76
|
-
*
|
|
77
|
-
* @param service - service name or class to check
|
|
78
|
-
* @returns true if service instance already exists, otherwise false.
|
|
79
|
-
* @throws {@link InvalidArgument} when service is null or empty
|
|
80
|
-
*/
|
|
81
|
-
isResolved<T>(service: string | Class<T> | TypedArray<T>, parent?: boolean): boolean;
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* Resolves single instance of class
|
|
85
|
-
*
|
|
86
|
-
* @param type - what to resolve, can be class definition or factory function
|
|
87
|
-
* @param options - options passed to constructor / factory
|
|
88
|
-
*/
|
|
89
|
-
resolve<T>(type: string, options?: unknown[], check?: boolean, tType?: Class<T>): T;
|
|
90
|
-
resolve<T>(type: string, check?: boolean): T;
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
* Resolves single instance of class
|
|
94
|
-
*
|
|
95
|
-
* @param type - what to resolve, can be class definition or factory function
|
|
96
|
-
* @param options - options passed to constructor / factory
|
|
97
|
-
*/
|
|
98
|
-
resolve<T>(type: Class<T>, options?: unknown[], check?: boolean): T extends AsyncService ? Promise<T> : T;
|
|
99
|
-
resolve<T>(type: Class<T>, check?: boolean): T extends AsyncService ? Promise<T> : T;
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* Resolves all instances of given class. Under single definition can be registered multiple implementations.
|
|
103
|
-
*
|
|
104
|
-
* @param type - typed array of specified type. since TS does not expose array metadata and type its uses TypedArray<T> consctruct
|
|
105
|
-
* @param options - options passed to constructor / factory
|
|
106
|
-
* @param check - strict check if serivice is registered in container before resolving. Default behavior is to not check and resolve
|
|
107
|
-
*
|
|
108
|
-
*/
|
|
109
|
-
resolve<T>(type: TypedArray<T>, options?: unknown[], check?: boolean): T extends AsyncService ? Promise<T[]> : T[];
|
|
110
|
-
resolve<T>(type: TypedArray<T>, check?: boolean): T extends AsyncService ? Promise<T[]> : T[];
|
|
111
|
-
getRegisteredTypes<T>(service: string | Class<T> | TypedArray<T>, parent?: boolean): (Class<unknown> | Factory<unknown>)[];
|
|
112
|
-
private resolveType;
|
|
113
|
-
protected getNewInstance(typeToCreate: Class<unknown> | Factory<unknown>, a?: IResolvedInjection[], options?: unknown[]): Promise<unknown> | unknown;
|
|
114
|
-
hasRegisteredType<T>(source: Class<T> | string, type: Class<T> | string | TypedArray<T>, parent?: boolean): boolean;
|
|
115
|
-
protected resolveDependencies(toInject: IToInject<unknown>[]): (Promise<{
|
|
116
|
-
autoinject: boolean;
|
|
117
|
-
autoinjectKey: string;
|
|
118
|
-
instance: any;
|
|
119
|
-
}> | {
|
|
120
|
-
autoinject: boolean;
|
|
121
|
-
autoinjectKey: string;
|
|
122
|
-
instance: any;
|
|
123
|
-
})[] | Promise<({
|
|
124
|
-
autoinject: boolean;
|
|
125
|
-
autoinjectKey: string;
|
|
126
|
-
instance: any;
|
|
127
|
-
} | {
|
|
128
|
-
autoinject: boolean;
|
|
129
|
-
autoinjectKey: string;
|
|
130
|
-
instance: any;
|
|
131
|
-
})[]>;
|
|
132
|
-
extractDescriptor(type: Class<unknown>): IInjectDescriptor<unknown>;
|
|
133
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
import { TypedArray } from './array.js';
|
|
4
|
+
import { IBind, IContainer, IInjectDescriptor, IResolvedInjection, IToInject, AsyncService, ResolvableObject } from './interfaces.js';
|
|
5
|
+
import { Class, Factory } from './types.js';
|
|
6
|
+
import { EventEmitter } from 'events';
|
|
7
|
+
import { Registry } from './registry.js';
|
|
8
|
+
import { ContainerCache } from './container-cache.js';
|
|
9
|
+
/**
|
|
10
|
+
* Dependency injection container implementation
|
|
11
|
+
*/
|
|
12
|
+
export declare class Container extends EventEmitter implements IContainer {
|
|
13
|
+
/**
|
|
14
|
+
* Handles information about what is registered as what
|
|
15
|
+
* eg. that class IConfiguration should be resolved as DatabaseConfiguration etc.
|
|
16
|
+
*/
|
|
17
|
+
private registry;
|
|
18
|
+
/**
|
|
19
|
+
* Singletons cache, objects that should be created only once are stored here.
|
|
20
|
+
*/
|
|
21
|
+
private cache;
|
|
22
|
+
/**
|
|
23
|
+
* Parent container if avaible
|
|
24
|
+
*/
|
|
25
|
+
private parent;
|
|
26
|
+
/**
|
|
27
|
+
* Returns container cache - map object with resolved classes as singletons
|
|
28
|
+
*/
|
|
29
|
+
get Cache(): ContainerCache;
|
|
30
|
+
get Registry(): Registry;
|
|
31
|
+
get Parent(): IContainer;
|
|
32
|
+
constructor(parent?: IContainer);
|
|
33
|
+
/**
|
|
34
|
+
* Clears container registry and cache. shorthand for container.clearCache() && container.clearRegistry()
|
|
35
|
+
*/
|
|
36
|
+
clear(): void;
|
|
37
|
+
dispose(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* clears container registered types information
|
|
40
|
+
*/
|
|
41
|
+
clearCache(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Clears container resolved types
|
|
44
|
+
*/
|
|
45
|
+
clearRegistry(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Register class/interface to DI.
|
|
48
|
+
* @param type - interface object to register
|
|
49
|
+
* @throws {@link InvalidArgument} if type is null or undefined
|
|
50
|
+
*/
|
|
51
|
+
register<T>(implementation: Class<T> | Factory<T> | ResolvableObject): IBind;
|
|
52
|
+
unregister<T>(implementation: string | Class<T> | Factory<T> | ResolvableObject): void;
|
|
53
|
+
uncache<T>(implementation: string | Class<T> | TypedArray<T>, parent?: boolean): void;
|
|
54
|
+
/**
|
|
55
|
+
* Creates child DI container.
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
child(): IContainer;
|
|
59
|
+
/**
|
|
60
|
+
* Gets already resolved services. Works only for singleton classes.
|
|
61
|
+
*
|
|
62
|
+
* Do not try to get service by factory func, it will always return null.
|
|
63
|
+
* If you somehowe want to cache instances created by factory functions,
|
|
64
|
+
* factory itself should do that somehow and end user should always resolve by
|
|
65
|
+
* assigned type
|
|
66
|
+
*
|
|
67
|
+
* @param serviceName - name of service to get
|
|
68
|
+
* @returns null if no service has been resolved at given name
|
|
69
|
+
*/
|
|
70
|
+
get<T>(service: TypedArray<T>, parent?: boolean): T[];
|
|
71
|
+
get<T>(service: string | Class<T>, parent?: boolean): T;
|
|
72
|
+
hasRegistered<T>(service: Class<T> | string, parent?: boolean): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if service is already resolved and exists in container cache.
|
|
75
|
+
* NOTE: check is only valid for classes that are singletons.
|
|
76
|
+
*
|
|
77
|
+
* @param service - service name or class to check
|
|
78
|
+
* @returns true if service instance already exists, otherwise false.
|
|
79
|
+
* @throws {@link InvalidArgument} when service is null or empty
|
|
80
|
+
*/
|
|
81
|
+
isResolved<T>(service: string | Class<T> | TypedArray<T>, parent?: boolean): boolean;
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* Resolves single instance of class
|
|
85
|
+
*
|
|
86
|
+
* @param type - what to resolve, can be class definition or factory function
|
|
87
|
+
* @param options - options passed to constructor / factory
|
|
88
|
+
*/
|
|
89
|
+
resolve<T>(type: string, options?: unknown[], check?: boolean, tType?: Class<T>): T;
|
|
90
|
+
resolve<T>(type: string, check?: boolean): T;
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* Resolves single instance of class
|
|
94
|
+
*
|
|
95
|
+
* @param type - what to resolve, can be class definition or factory function
|
|
96
|
+
* @param options - options passed to constructor / factory
|
|
97
|
+
*/
|
|
98
|
+
resolve<T>(type: Class<T>, options?: unknown[], check?: boolean): T extends AsyncService ? Promise<T> : T;
|
|
99
|
+
resolve<T>(type: Class<T>, check?: boolean): T extends AsyncService ? Promise<T> : T;
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* Resolves all instances of given class. Under single definition can be registered multiple implementations.
|
|
103
|
+
*
|
|
104
|
+
* @param type - typed array of specified type. since TS does not expose array metadata and type its uses TypedArray<T> consctruct
|
|
105
|
+
* @param options - options passed to constructor / factory
|
|
106
|
+
* @param check - strict check if serivice is registered in container before resolving. Default behavior is to not check and resolve
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
resolve<T>(type: TypedArray<T>, options?: unknown[], check?: boolean): T extends AsyncService ? Promise<T[]> : T[];
|
|
110
|
+
resolve<T>(type: TypedArray<T>, check?: boolean): T extends AsyncService ? Promise<T[]> : T[];
|
|
111
|
+
getRegisteredTypes<T>(service: string | Class<T> | TypedArray<T>, parent?: boolean): (Class<unknown> | Factory<unknown>)[];
|
|
112
|
+
private resolveType;
|
|
113
|
+
protected getNewInstance(typeToCreate: Class<unknown> | Factory<unknown>, a?: IResolvedInjection[], options?: unknown[]): Promise<unknown> | unknown;
|
|
114
|
+
hasRegisteredType<T>(source: Class<T> | string, type: Class<T> | string | TypedArray<T>, parent?: boolean): boolean;
|
|
115
|
+
protected resolveDependencies(toInject: IToInject<unknown>[]): (Promise<{
|
|
116
|
+
autoinject: boolean;
|
|
117
|
+
autoinjectKey: string;
|
|
118
|
+
instance: any;
|
|
119
|
+
}> | {
|
|
120
|
+
autoinject: boolean;
|
|
121
|
+
autoinjectKey: string;
|
|
122
|
+
instance: any;
|
|
123
|
+
})[] | Promise<({
|
|
124
|
+
autoinject: boolean;
|
|
125
|
+
autoinjectKey: string;
|
|
126
|
+
instance: any;
|
|
127
|
+
} | {
|
|
128
|
+
autoinject: boolean;
|
|
129
|
+
autoinjectKey: string;
|
|
130
|
+
instance: any;
|
|
131
|
+
})[]>;
|
|
132
|
+
extractDescriptor(type: Class<unknown>): IInjectDescriptor<unknown>;
|
|
133
|
+
}
|
|
134
134
|
//# sourceMappingURL=container.d.ts.map
|