Skip to content

Commit e14bdb2

Browse files
authored
feat: remove context egg object factory (#93)
1 parent ec7bc2c commit e14bdb2

6 files changed

Lines changed: 12 additions & 56 deletions

File tree

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
export * from './src/impl/EggContextObjectFactory';
2-
export * from './src/impl/EggSingletonObjectFactory';
1+
export * from './src/EggObjectFactory';
32

43
import './src/EggObjectFactoryPrototype';
54
import './src/EggObjectFactoryObject';

core/dynamic-inject-runtime/src/AbstractEggObjectFactory.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

core/dynamic-inject-runtime/src/impl/EggSingletonObjectFactory.ts renamed to core/dynamic-inject-runtime/src/EggObjectFactory.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import type { EggContainerFactory } from '@eggjs/tegg-runtime';
2-
import { EggAbstractClazz, QualifierImplUtil } from '@eggjs/tegg-dynamic-inject';
2+
import { EggAbstractClazz, EggObjectFactory as IEggObjectFactory, QualifierImplUtil } from '@eggjs/tegg-dynamic-inject';
33
import { AccessLevel, PrototypeUtil, QualifierValue, SingletonProto } from '@eggjs/core-decorator';
4-
import { AbstractEggObjectFactory } from '../AbstractEggObjectFactory';
5-
import { EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE } from '../EggObjectFactoryPrototype';
4+
import { EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE } from './EggObjectFactoryPrototype';
65

76
@SingletonProto({
87
protoImplType: EGG_OBJECT_FACTORY_PROTO_IMPLE_TYPE,
98
name: 'eggObjectFactory',
109
accessLevel: AccessLevel.PUBLIC,
1110
})
12-
export class EggSingletonObjectFactory extends AbstractEggObjectFactory {
11+
export class EggObjectFactory implements IEggObjectFactory {
1312
eggContainerFactory: typeof EggContainerFactory;
1413

1514
async getEggObject<T extends object>(abstractClazz: EggAbstractClazz<T>, qualifierValue: QualifierValue) {

core/dynamic-inject-runtime/src/EggObjectFactoryObject.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import {
22
EggContainerFactory,
33
EggContext,
44
EggObject,
5-
EggObjectLifeCycleContext,
65
EggObjectFactory as TEggObjectFactory,
76
} from '@eggjs/tegg-runtime';
87
import { EggObjectFactoryPrototype } from './EggObjectFactoryPrototype';
98
import { EggObjectName } from '@eggjs/core-decorator';
109
import { IdenticalUtil } from '@eggjs/tegg-lifecycle';
1110
import { EggPrototype } from '@eggjs/tegg-metadata';
12-
import { AbstractEggObjectFactory } from './AbstractEggObjectFactory';
11+
import { EggObjectFactory } from './EggObjectFactory';
1312

1413
const OBJ = Symbol('EggObjectFactoryObject#obj');
1514

@@ -18,26 +17,24 @@ export class EggObjectFactoryObject implements EggObject {
1817
readonly name: EggObjectName;
1918
readonly ctx?: EggContext;
2019
readonly id: string;
21-
private [OBJ]: AbstractEggObjectFactory;
20+
private [OBJ]: EggObjectFactory;
2221

23-
constructor(name: EggObjectName, proto: EggObjectFactoryPrototype, ctx?: EggContext) {
22+
constructor(name: EggObjectName, proto: EggObjectFactoryPrototype) {
2423
this.proto = proto;
2524
this.name = name;
26-
this.ctx = ctx;
2725
this.id = IdenticalUtil.createObjectId(this.proto.id, this.ctx?.id);
2826
}
2927

3028
get obj() {
3129
if (!this[OBJ]) {
32-
this[OBJ] = this.proto.constructEggObject() as AbstractEggObjectFactory;
30+
this[OBJ] = this.proto.constructEggObject() as EggObjectFactory;
3331
this[OBJ].eggContainerFactory = EggContainerFactory;
34-
this[OBJ].eggContext = this.ctx;
3532
}
3633
return this[OBJ];
3734
}
3835

39-
static async createObject(name: EggObjectName, proto: EggPrototype, _: EggObjectLifeCycleContext, ctx?: EggContext): Promise<EggObjectFactoryObject> {
40-
return new EggObjectFactoryObject(name, proto as EggObjectFactoryPrototype, ctx);
36+
static async createObject(name: EggObjectName, proto: EggPrototype): Promise<EggObjectFactoryObject> {
37+
return new EggObjectFactoryObject(name, proto as EggObjectFactoryPrototype);
4138
}
4239

4340
readonly isReady: true;

core/dynamic-inject-runtime/src/impl/EggContextObjectFactory.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

plugin/tegg/lib/EggAppLoader.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { ObjectUtils } from '@eggjs/tegg-common-util';
1111
import { COMPATIBLE_PROTO_IMPLE_TYPE } from './EggCompatibleProtoImpl';
1212
import { BackgroundTaskHelper } from '@eggjs/tegg-background-task';
13-
import { EggContextObjectFactory, EggSingletonObjectFactory } from '@eggjs/tegg-dynamic-inject-runtime';
13+
import { EggObjectFactory } from '@eggjs/tegg-dynamic-inject-runtime';
1414

1515
const APP_CLAZZ_BLACK_LIST = [ 'eggObjectFactory' ];
1616
const DEFAULT_APP_CLAZZ = [];
@@ -142,8 +142,7 @@ export class EggAppLoader implements Loader {
142142
// inner helper class list
143143
// TODO: should auto the inner class
144144
BackgroundTaskHelper,
145-
EggContextObjectFactory,
146-
EggSingletonObjectFactory,
145+
EggObjectFactory,
147146
];
148147
}
149148
}

0 commit comments

Comments
 (0)