( identifier, target, targetKey, isLazyInject = false, parameterIndex?: number )
| 28 | } |
| 29 | |
| 30 | export function saveInjectMetadata( |
| 31 | identifier, |
| 32 | target, |
| 33 | targetKey, |
| 34 | isLazyInject = false, |
| 35 | parameterIndex?: number |
| 36 | ) { |
| 37 | // 1、use identifier by user |
| 38 | // let identifier = opts.identifier; |
| 39 | let injectMode = InjectModeEnum.Identifier; |
| 40 | let id = identifier; |
| 41 | const isConstructor = parameterIndex !== undefined; |
| 42 | // 2、use identifier by class uuid |
| 43 | if (isConstructor) { |
| 44 | const paramNames = getConstructParamNames(target); |
| 45 | |
| 46 | if (!id) { |
| 47 | const argsTypes = MetadataManager.getMethodParamTypes(target, targetKey); |
| 48 | const type = MetadataManager.transformTypeFromTSDesign( |
| 49 | argsTypes[parameterIndex] |
| 50 | ); |
| 51 | if ( |
| 52 | !type.isBaseType && |
| 53 | isClass(type.originDesign) && |
| 54 | DecoratorManager.isProvide(type.originDesign) |
| 55 | ) { |
| 56 | id = DecoratorManager.getProviderUUId(type.originDesign as ClassType); |
| 57 | injectMode = InjectModeEnum.Class; |
| 58 | } |
| 59 | if (!id) { |
| 60 | // 3、use identifier by property name |
| 61 | id = paramNames[parameterIndex]; |
| 62 | injectMode = InjectModeEnum.SelfName; |
| 63 | } |
| 64 | } |
| 65 | MetadataManager.attachMetadata( |
| 66 | CONSTRUCTOR_INJECT_KEY, |
| 67 | { |
| 68 | targetKey, |
| 69 | id, |
| 70 | name: paramNames[parameterIndex], |
| 71 | injectMode, |
| 72 | isLazyInject, |
| 73 | parameterIndex, |
| 74 | }, |
| 75 | target, |
| 76 | 'default' |
| 77 | ); |
| 78 | } else { |
| 79 | if (!id) { |
| 80 | const type = MetadataManager.transformTypeFromTSDesign( |
| 81 | MetadataManager.getPropertyType(target, targetKey) |
| 82 | ); |
| 83 | if ( |
| 84 | !type.isBaseType && |
| 85 | isClass(type.originDesign) && |
| 86 | DecoratorManager.isProvide(type.originDesign) |
| 87 | ) { |
no test coverage detected