@midwayjs/core 3.0.0-alpha.28 → 3.0.0-alpha.41
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/dist/baseFramework.js +4 -33
- package/dist/common/reflectTool.d.ts +3 -1
- package/dist/context/container.d.ts +45 -23
- package/dist/context/container.js +199 -202
- package/dist/context/definitionRegistry.d.ts +26 -0
- package/dist/context/definitionRegistry.js +124 -0
- package/dist/context/managedResolverFactory.d.ts +15 -19
- package/dist/context/managedResolverFactory.js +27 -256
- package/dist/context/providerWrapper.d.ts +2 -3
- package/dist/context/requestContainer.js +7 -10
- package/dist/context/resolverHandler.d.ts +2 -2
- package/dist/context/resolverHandler.js +1 -1
- package/dist/definitions/functionDefinition.d.ts +0 -2
- package/dist/definitions/functionDefinition.js +0 -6
- package/dist/definitions/objectDefinition.d.ts +1 -4
- package/dist/definitions/objectDefinition.js +0 -8
- package/dist/definitions/properties.d.ts +0 -2
- package/dist/definitions/properties.js +5 -21
- package/dist/features/pipeline.d.ts +3 -3
- package/dist/functional/configuration.d.ts +2 -0
- package/dist/functional/configuration.js +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -23
- package/dist/interface.d.ts +21 -32
- package/dist/util/containerUtil.js +1 -1
- package/dist/util/webRouterCollector.d.ts +8 -0
- package/dist/util/webRouterCollector.js +63 -119
- package/package.json +5 -4
- package/dist/context/applicationContext.d.ts +0 -81
- package/dist/context/applicationContext.js +0 -263
- package/dist/context/managed.d.ts +0 -45
- package/dist/context/managed.js +0 -69
- package/dist/util/staticConfig.d.ts +0 -10
- package/dist/util/staticConfig.js +0 -67
package/dist/baseFramework.js
CHANGED
|
@@ -107,11 +107,6 @@ class BaseFramework {
|
|
|
107
107
|
await this.initializeLogger(options);
|
|
108
108
|
}
|
|
109
109
|
async containerDirectoryLoad(options) {
|
|
110
|
-
if (options.applicationContext) {
|
|
111
|
-
// 如果有传入全局容器,就不需要再次扫描了
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
// 废弃 deprecated
|
|
115
110
|
if (options.preloadModules && options.preloadModules.length) {
|
|
116
111
|
for (const preloadModule of options.preloadModules) {
|
|
117
112
|
this.applicationContext.bindClass(preloadModule);
|
|
@@ -281,7 +276,7 @@ class BaseFramework {
|
|
|
281
276
|
}
|
|
282
277
|
else {
|
|
283
278
|
// 普通类写法
|
|
284
|
-
const providerId = (0, decorator_1.
|
|
279
|
+
const providerId = (0, decorator_1.getProviderUUId)(cycle.target);
|
|
285
280
|
if (this.getApplicationContext().registry.hasDefinition(providerId)) {
|
|
286
281
|
cycle.instance =
|
|
287
282
|
await this.getApplicationContext().getAsync(providerId);
|
|
@@ -300,22 +295,7 @@ class BaseFramework {
|
|
|
300
295
|
}
|
|
301
296
|
for (const cycle of lifecycleInstanceList) {
|
|
302
297
|
if (typeof cycle.instance.onReady === 'function') {
|
|
303
|
-
|
|
304
|
-
* 让组件能正确获取到 bind 之后 registerObject 的对象有三个方法
|
|
305
|
-
* 1、在 load 之后修改 bind,不太可行
|
|
306
|
-
* 2、每次 getAsync 的时候,去掉 namespace,同时还要查找当前全局的变量,性能差
|
|
307
|
-
* 3、一般只会在 onReady 的地方执行 registerObject(否则没有全局的意义),这个取巧的办法就是 onReady 传入一个代理,其中绑定当前的 namespace
|
|
308
|
-
*/
|
|
309
|
-
await cycle.instance.onReady(new Proxy(this.getApplicationContext(), {
|
|
310
|
-
get: function (target, prop, receiver) {
|
|
311
|
-
if (prop === 'getCurrentNamespace' && cycle.namespace) {
|
|
312
|
-
return () => {
|
|
313
|
-
return cycle.namespace;
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
return Reflect.get(target, prop, receiver);
|
|
317
|
-
},
|
|
318
|
-
}), this.app);
|
|
298
|
+
await cycle.instance.onReady(this.getApplicationContext(), this.app);
|
|
319
299
|
}
|
|
320
300
|
}
|
|
321
301
|
}
|
|
@@ -328,20 +308,11 @@ class BaseFramework {
|
|
|
328
308
|
inst = cycle.target;
|
|
329
309
|
}
|
|
330
310
|
else {
|
|
331
|
-
const providerId = (0, decorator_1.
|
|
311
|
+
const providerId = (0, decorator_1.getProviderUUId)(cycle.target);
|
|
332
312
|
inst = await this.applicationContext.getAsync(providerId);
|
|
333
313
|
}
|
|
334
314
|
if (inst.onStop && typeof inst.onStop === 'function') {
|
|
335
|
-
await inst.onStop(
|
|
336
|
-
get: function (target, prop, receiver) {
|
|
337
|
-
if (prop === 'getCurrentNamespace' && cycle.namespace) {
|
|
338
|
-
return () => {
|
|
339
|
-
return cycle.namespace;
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
return Reflect.get(target, prop, receiver);
|
|
343
|
-
},
|
|
344
|
-
}), this.app);
|
|
315
|
+
await inst.onStop(this.getApplicationContext(), this.app);
|
|
345
316
|
}
|
|
346
317
|
}
|
|
347
318
|
}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ObjectDefinitionOptions, ObjectIdentifier } from '@midwayjs/decorator';
|
|
3
3
|
import * as util from 'util';
|
|
4
|
-
import {
|
|
5
|
-
import { IConfigService, IEnvironmentService, IFileDetector, IInformationService, IMidwayContainer, IObjectDefinitionMetadata } from '../interface';
|
|
4
|
+
import { IConfigService, IEnvironmentService, IFileDetector, IIdentifierRelationShip, IInformationService, IMidwayContainer, IObjectDefinition, IObjectDefinitionRegistry } from '../interface';
|
|
6
5
|
import { ResolverHandler } from './resolverHandler';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
addImports(imports?: any[]): void;
|
|
14
|
-
bindConfigurationClass(clzz: any, filePath?: string): void;
|
|
15
|
-
private getConfigurationExport;
|
|
16
|
-
}
|
|
17
|
-
export declare class MidwayContainer extends BaseApplicationContext implements IMidwayContainer {
|
|
6
|
+
import { ManagedResolverFactory } from './managedResolverFactory';
|
|
7
|
+
export declare class MidwayContainer implements IMidwayContainer {
|
|
8
|
+
private _resolverFactory;
|
|
9
|
+
private _registry;
|
|
10
|
+
private _identifierMapping;
|
|
11
|
+
parent: IMidwayContainer;
|
|
18
12
|
private debugLogger;
|
|
19
|
-
private definitionMetadataList;
|
|
20
13
|
protected resolverHandler: ResolverHandler;
|
|
21
14
|
protected ctx: {};
|
|
22
15
|
protected configService: IConfigService;
|
|
@@ -26,18 +19,19 @@ export declare class MidwayContainer extends BaseApplicationContext implements I
|
|
|
26
19
|
private fileDetector;
|
|
27
20
|
private attrMap;
|
|
28
21
|
private isLoad;
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
constructor(parent?: IMidwayContainer);
|
|
23
|
+
protected init(): void;
|
|
24
|
+
get registry(): IObjectDefinitionRegistry;
|
|
25
|
+
set registry(registry: IObjectDefinitionRegistry);
|
|
26
|
+
get managedResolverFactory(): ManagedResolverFactory;
|
|
27
|
+
get identifierMapping(): IIdentifierRelationShip;
|
|
28
|
+
protected initService(): void;
|
|
31
29
|
load(module?: any): void;
|
|
32
|
-
loadDefinitions(): void;
|
|
33
|
-
createConfiguration(): ContainerConfiguration;
|
|
30
|
+
protected loadDefinitions(): void;
|
|
34
31
|
bindClass(exports: any, namespace?: string, filePath?: string): void;
|
|
35
32
|
bind<T>(target: T, options?: ObjectDefinitionOptions): void;
|
|
36
33
|
bind<T>(identifier: ObjectIdentifier, target: T, options?: ObjectDefinitionOptions): void;
|
|
37
|
-
protected
|
|
38
|
-
protected restoreDefinitions(definitionMetadataList: any): void;
|
|
39
|
-
protected getDefinitionMetaList(): any[];
|
|
40
|
-
protected bindModule(module: any, namespace?: string, filePath?: string): void;
|
|
34
|
+
protected bindModule(module: any, options?: ObjectDefinitionOptions): void;
|
|
41
35
|
getDebugLogger(): util.DebugLogger;
|
|
42
36
|
setFileDetector(fileDetector: IFileDetector): void;
|
|
43
37
|
createChild(): IMidwayContainer;
|
|
@@ -51,6 +45,34 @@ export declare class MidwayContainer extends BaseApplicationContext implements I
|
|
|
51
45
|
getResolverHandler(): ResolverHandler;
|
|
52
46
|
setAttr(key: string, value: any): void;
|
|
53
47
|
getAttr<T>(key: string): T;
|
|
48
|
+
protected getIdentifier(target: any): string;
|
|
49
|
+
protected findRegisterObject(identifier: any): any;
|
|
50
|
+
protected getManagedResolverFactory(): ManagedResolverFactory;
|
|
51
|
+
stop(): Promise<void>;
|
|
52
|
+
ready(): Promise<void>;
|
|
53
|
+
get<T>(identifier: {
|
|
54
|
+
new (...args: any[]): T;
|
|
55
|
+
}, args?: any): T;
|
|
56
|
+
get<T>(identifier: ObjectIdentifier, args?: any): T;
|
|
57
|
+
getAsync<T>(identifier: {
|
|
58
|
+
new (...args: any[]): T;
|
|
59
|
+
}, args?: any): Promise<T>;
|
|
60
|
+
getAsync<T>(identifier: ObjectIdentifier, args?: any): Promise<T>;
|
|
61
|
+
/**
|
|
62
|
+
* proxy registry.registerObject
|
|
63
|
+
* @param {ObjectIdentifier} identifier
|
|
64
|
+
* @param target
|
|
65
|
+
*/
|
|
66
|
+
registerObject(identifier: ObjectIdentifier, target: any): void;
|
|
67
|
+
/**
|
|
68
|
+
* register handler after instance create
|
|
69
|
+
* @param fn
|
|
70
|
+
*/
|
|
71
|
+
afterEachCreated(fn: (ins: any, context: IMidwayContainer, definition?: IObjectDefinition) => void): void;
|
|
72
|
+
/**
|
|
73
|
+
* register handler before instance create
|
|
74
|
+
* @param fn
|
|
75
|
+
*/
|
|
76
|
+
beforeEachCreated(fn: (Clzz: any, constructorArgs: any[], context: IMidwayContainer) => void): void;
|
|
54
77
|
}
|
|
55
|
-
export {};
|
|
56
78
|
//# sourceMappingURL=container.d.ts.map
|