( ctor: Constructor<T>, ctx: Context, session?: ResolutionSession, // eslint-disable-next-line @typescript-eslint/no-explicit-any nonInjectedArgs?: any[], )
| 45 | * @param nonInjectedArgs - Optional array of args for non-injected parameters |
| 46 | */ |
| 47 | export function instantiateClass<T extends object>( |
| 48 | ctor: Constructor<T>, |
| 49 | ctx: Context, |
| 50 | session?: ResolutionSession, |
| 51 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 52 | nonInjectedArgs?: any[], |
| 53 | ): ValueOrPromise<T> { |
| 54 | /* istanbul ignore if */ |
| 55 | if (debug.enabled) { |
| 56 | debug('Instantiating %s', getTargetName(ctor)); |
| 57 | if (nonInjectedArgs?.length) { |
| 58 | debug('Non-injected arguments:', nonInjectedArgs); |
| 59 | } |
| 60 | } |
| 61 | const argsOrPromise = resolveInjectedArguments( |
| 62 | ctor, |
| 63 | '', |
| 64 | ctx, |
| 65 | session, |
| 66 | nonInjectedArgs, |
| 67 | ); |
| 68 | const propertiesOrPromise = resolveInjectedProperties(ctor, ctx, session); |
| 69 | const inst: ValueOrPromise<T> = transformValueOrPromise( |
| 70 | argsOrPromise, |
| 71 | args => { |
| 72 | /* istanbul ignore if */ |
| 73 | if (debug.enabled) { |
| 74 | debug('Injected arguments for %s():', ctor.name, args); |
| 75 | } |
| 76 | return new ctor(...args); |
| 77 | }, |
| 78 | ); |
| 79 | return transformValueOrPromise(propertiesOrPromise, props => { |
| 80 | /* istanbul ignore if */ |
| 81 | if (debug.enabled) { |
| 82 | debug('Injected properties for %s:', ctor.name, props); |
| 83 | } |
| 84 | return transformValueOrPromise<T, T>(inst, obj => |
| 85 | Object.assign(obj, props), |
| 86 | ); |
| 87 | }); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * If the scope of current binding is `SINGLETON`, reset the context |
no test coverage detected