Skip to content

Commit 45320f0

Browse files
committed
feat: support optional inject in constructor
1 parent 8a45b8f commit 45320f0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

core/core-decorator/src/decorator/Inject.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ export function Inject(param?: InjectParams | string) {
3636
function constructorInject(target: any, parameterIndex: number) {
3737
const argNames = ObjectUtils.getConstructorArgNameList(target);
3838
const argName = argNames[parameterIndex];
39-
// TODO get objName from design:type
40-
const objName = typeof param === 'string' ? param : param?.name;
4139
const injectObject: InjectConstructorInfo = {
4240
refIndex: parameterIndex,
4341
refName: argName,
44-
objName: objName || argName,
42+
// TODO get objName from design:type
43+
objName: injectParam?.name || argName,
4544
};
4645

46+
if (injectParam?.optional) {
47+
injectObject.optional = true;
48+
}
49+
4750
PrototypeUtil.setInjectType(target, InjectType.CONSTRUCTOR);
4851
PrototypeUtil.addInjectConstructor(target as EggProtoImplClass, injectObject);
4952
}

core/types/core-decorator/model/InjectConstructorInfo.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ export interface InjectConstructorInfo {
1313
* obj's name will be injected
1414
*/
1515
objName: EggObjectName;
16+
/**
17+
* optional inject
18+
*/
19+
optional?: boolean;
1620
}

0 commit comments

Comments
 (0)