(
type: Type<T>,
moduleRef: Module,
contextId?: ContextId,
)
| 161 | } |
| 162 | |
| 163 | protected async instantiateClass<T = any>( |
| 164 | type: Type<T>, |
| 165 | moduleRef: Module, |
| 166 | contextId?: ContextId, |
| 167 | ): Promise<T> { |
| 168 | const wrapper = new InstanceWrapper({ |
| 169 | name: type && type.name, |
| 170 | metatype: type, |
| 171 | isResolved: false, |
| 172 | scope: getClassScope(type), |
| 173 | durable: isDurable(type), |
| 174 | host: moduleRef, |
| 175 | }); |
| 176 | |
| 177 | if (type?.prototype) { |
| 178 | wrapper.setInstanceByContextId(contextId ?? STATIC_CONTEXT, { |
| 179 | instance: Object.create(type.prototype), |
| 180 | isResolved: false, |
| 181 | isPending: false, |
| 182 | }); |
| 183 | } |
| 184 | |
| 185 | return new Promise<T>(async (resolve, reject) => { |
| 186 | try { |
| 187 | const callback = async (instances: any[]) => { |
| 188 | const properties = await this.injector.resolveProperties( |
| 189 | wrapper, |
| 190 | moduleRef, |
| 191 | undefined, |
| 192 | { |
| 193 | contextId: contextId ?? STATIC_CONTEXT, |
| 194 | inquirer: wrapper, |
| 195 | }, |
| 196 | ); |
| 197 | const instance = new type(...instances); |
| 198 | this.injector.applyProperties(instance, properties); |
| 199 | resolve(instance); |
| 200 | }; |
| 201 | await this.injector.resolveConstructorParams<T>( |
| 202 | wrapper, |
| 203 | moduleRef, |
| 204 | undefined, |
| 205 | callback, |
| 206 | { |
| 207 | contextId: contextId ?? STATIC_CONTEXT, |
| 208 | inquirer: wrapper, |
| 209 | }, |
| 210 | ); |
| 211 | } catch (err) { |
| 212 | reject(err); |
| 213 | } |
| 214 | }); |
| 215 | } |
| 216 | } |
nothing calls this directly
no test coverage detected