@@ -98,7 +98,7 @@ export class EggPrototypeBuilder {
98
98
) ) ;
99
99
}
100
100
101
- private findInjectObjectPrototype ( injectObject : InjectObject ) : EggPrototype {
101
+ private findInjectObjectPrototype ( injectObject : InjectObject | InjectConstructor ) : EggPrototype {
102
102
const propertyQualifiers = QualifierUtil . getProperQualifiers ( this . clazz , injectObject . refName ) ;
103
103
try {
104
104
return this . tryFindDefaultPrototype ( injectObject ) ;
@@ -121,22 +121,34 @@ export class EggPrototypeBuilder {
121
121
const injectObjectProtos : Array < InjectObjectProto | InjectConstructorProto > = [ ] ;
122
122
for ( const injectObject of this . injectObjects ) {
123
123
const propertyQualifiers = QualifierUtil . getProperQualifiers ( this . clazz , injectObject . refName ) ;
124
- const proto = this . findInjectObjectPrototype ( injectObject ) ;
125
- if ( this . injectType === InjectType . PROPERTY ) {
126
- injectObjectProtos . push ( {
127
- refName : injectObject . refName ,
128
- objName : injectObject . objName ,
129
- qualifiers : propertyQualifiers ,
130
- proto,
131
- } ) ;
132
- } else {
133
- injectObjectProtos . push ( {
134
- refIndex : ( injectObject as InjectConstructor ) . refIndex ,
135
- refName : injectObject . refName ,
136
- objName : injectObject . objName ,
137
- qualifiers : propertyQualifiers ,
138
- proto,
139
- } ) ;
124
+ try {
125
+ const proto = this . findInjectObjectPrototype ( injectObject ) ;
126
+ let injectObjectProto : InjectObjectProto | InjectConstructorProto ;
127
+ if ( this . injectType === InjectType . PROPERTY ) {
128
+ injectObjectProto = {
129
+ refName : injectObject . refName ,
130
+ objName : injectObject . objName ,
131
+ qualifiers : propertyQualifiers ,
132
+ proto,
133
+ } ;
134
+ } else {
135
+ injectObjectProto = {
136
+ refIndex : ( injectObject as InjectConstructor ) . refIndex ,
137
+ refName : injectObject . refName ,
138
+ objName : injectObject . objName ,
139
+ qualifiers : propertyQualifiers ,
140
+ proto,
141
+ } ;
142
+ }
143
+ if ( injectObject . optional ) {
144
+ injectObject . optional = true ;
145
+ }
146
+ injectObjectProtos . push ( injectObjectProto ) ;
147
+ } catch ( e ) {
148
+ if ( e instanceof EggPrototypeNotFound && injectObject . optional ) {
149
+ continue ;
150
+ }
151
+ throw e ;
140
152
}
141
153
}
142
154
const id = IdenticalUtil . createProtoId ( this . loadUnit . id , this . name ) ;
0 commit comments