diff --git a/core/core-decorator/src/decorator/MultiInstanceProto.ts b/core/core-decorator/src/decorator/MultiInstanceProto.ts index ec76110a..fc638af0 100644 --- a/core/core-decorator/src/decorator/MultiInstanceProto.ts +++ b/core/core-decorator/src/decorator/MultiInstanceProto.ts @@ -52,17 +52,18 @@ export function MultiInstanceProto(param: MultiInstancePrototypeParams) { const property: EggMultiInstancePrototypeInfo = { ...DEFAULT_PARAMS, ...param as MultiInstancePrototypeStaticParams, + className: clazz.name, }; PrototypeUtil.setMultiInstanceStaticProperty(clazz, property); } else if ((param as MultiInstancePrototypeCallbackParams).getObjects) { const property: EggMultiInstanceCallbackPrototypeInfo = { ...DEFAULT_PARAMS, ...param as MultiInstancePrototypeCallbackParams, + className: clazz.name, }; PrototypeUtil.setMultiInstanceCallbackProperty(clazz, property); } - // './tegg/core/common-util/src/StackUtil.ts', // './tegg/core/core-decorator/src/decorator/Prototype.ts', // './tegg/core/core-decorator/node_modules/_reflect-metadata@0.1.13@reflect-metadata/Reflect.js', diff --git a/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts b/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts index b3a1ea96..89e90a12 100644 --- a/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts +++ b/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts @@ -13,6 +13,10 @@ export interface MultiInstancePrototypeGetObjectsContext { } export interface EggMultiInstancePrototypeInfo { + /** + * The class name of the object + */ + className: string; /** * obj init type */ @@ -33,6 +37,10 @@ export interface EggMultiInstancePrototypeInfo { } export interface EggMultiInstanceCallbackPrototypeInfo { + /** + * The class name of the object + */ + className: string; /** * obj init type */ diff --git a/core/core-decorator/src/model/EggPrototypeInfo.ts b/core/core-decorator/src/model/EggPrototypeInfo.ts index 53779c3e..52762e18 100644 --- a/core/core-decorator/src/model/EggPrototypeInfo.ts +++ b/core/core-decorator/src/model/EggPrototypeInfo.ts @@ -10,6 +10,10 @@ export interface EggPrototypeInfo { * egg object name */ name: EggPrototypeName; + /** + * The class name of the object + */ + className: string; /** * obj init type */ @@ -26,8 +30,4 @@ export interface EggPrototypeInfo { * EggPrototype qualifiers */ qualifiers?: QualifierInfo[]; - /** - * The class name of the object - */ - className?: string; } diff --git a/core/metadata/src/factory/EggPrototypeCreatorFactory.ts b/core/metadata/src/factory/EggPrototypeCreatorFactory.ts index aa8760d1..a3efb42f 100644 --- a/core/metadata/src/factory/EggPrototypeCreatorFactory.ts +++ b/core/metadata/src/factory/EggPrototypeCreatorFactory.ts @@ -28,6 +28,7 @@ export class EggPrototypeCreatorFactory { initType: multiInstanceProtoInfo.initType, accessLevel: multiInstanceProtoInfo.accessLevel, qualifiers: obj.qualifiers, + className: multiInstanceProtoInfo.className, }); } } else { diff --git a/core/metadata/src/impl/EggPrototypeBuilder.ts b/core/metadata/src/impl/EggPrototypeBuilder.ts index 48e6a153..a4c64605 100644 --- a/core/metadata/src/impl/EggPrototypeBuilder.ts +++ b/core/metadata/src/impl/EggPrototypeBuilder.ts @@ -40,6 +40,7 @@ export class EggPrototypeBuilder { private injectObjects: Array = []; private loadUnit: LoadUnit; private qualifiers: QualifierInfo[] = []; + private className: string; static create(ctx: EggPrototypeLifecycleContext): EggPrototype { const { clazz, loadUnit } = ctx; @@ -48,6 +49,7 @@ export class EggPrototypeBuilder { const builder = new EggPrototypeBuilder(); builder.clazz = clazz; builder.name = ctx.prototypeInfo.name; + builder.className = ctx.prototypeInfo.className; builder.initType = ctx.prototypeInfo.initType; builder.accessLevel = ctx.prototypeInfo.accessLevel; builder.filepath = filepath!; @@ -131,6 +133,7 @@ export class EggPrototypeBuilder { injectObjectProtos, this.loadUnit.id, this.qualifiers, + this.className, ); } } diff --git a/core/metadata/src/impl/EggPrototypeImpl.ts b/core/metadata/src/impl/EggPrototypeImpl.ts index 6d0d8fe5..e14ef9d0 100644 --- a/core/metadata/src/impl/EggPrototypeImpl.ts +++ b/core/metadata/src/impl/EggPrototypeImpl.ts @@ -20,6 +20,7 @@ export class EggPrototypeImpl implements EggPrototype { readonly accessLevel: AccessLevel; readonly injectObjects: InjectObjectProto[]; readonly loadUnitId: Id; + readonly className: string; constructor( id: string, @@ -31,6 +32,7 @@ export class EggPrototypeImpl implements EggPrototype { injectObjectMap: InjectObjectProto[], loadUnitId: Id, qualifiers: QualifierInfo[], + className: string, ) { this.id = id; this.clazz = clazz; @@ -41,6 +43,7 @@ export class EggPrototypeImpl implements EggPrototype { this.injectObjects = injectObjectMap; this.loadUnitId = loadUnitId; this.qualifiers = qualifiers; + this.className = className; } verifyQualifiers(qualifiers: QualifierInfo[]): boolean { diff --git a/core/metadata/src/model/EggPrototype.ts b/core/metadata/src/model/EggPrototype.ts index 790f2aed..73d8c817 100644 --- a/core/metadata/src/model/EggPrototype.ts +++ b/core/metadata/src/model/EggPrototype.ts @@ -45,6 +45,7 @@ export interface EggPrototype extends LifecycleObject { const appRepoProto = loadUnit.getEggPrototype('appRepo', [{ attribute: InitTypeQualifierAttribute, value: ObjectInitType.SINGLETON }]); const sprintRepoProto = loadUnit.getEggPrototype('sprintRepo', [{ attribute: InitTypeQualifierAttribute, value: ObjectInitType.SINGLETON }]); const userRepoProto = loadUnit.getEggPrototype('userRepo', [{ attribute: InitTypeQualifierAttribute, value: ObjectInitType.SINGLETON }]); - assert(appRepoProto); - assert(sprintRepoProto); - assert(userRepoProto); + assert.strictEqual(appRepoProto.length, 1); + assert.strictEqual(appRepoProto[0].className, 'AppRepo'); + assert.strictEqual(sprintRepoProto.length, 1); + assert.strictEqual(userRepoProto.length, 1); await LoadUnitFactory.destroyLoadUnit(loadUnit); }); @@ -92,6 +93,7 @@ describe('test/LoadUnit/LoadUnit.test.ts', () => { const foo2Prototype = loadUnit.getEggPrototype('foo', [{ attribute: FOO_ATTRIBUTE, value: 'foo2' }]); assert(foo1Prototype); assert(foo1Prototype.length === 1); + assert.strictEqual(foo1Prototype[0].className, 'FooLogger'); assert(foo2Prototype); assert(foo2Prototype.length === 1); await LoadUnitFactory.destroyLoadUnit(loadUnit);