Skip to content

Commit 6b97b11

Browse files
Merge pull request nestjs#1324 from nestjs/bugfix/928-direct-instance
bugfix(core) use direct class instance
2 parents 58d7300 + 5a6f64a commit 6b97b11

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

packages/core/injector/injector.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ export class Injector {
227227
module: Module,
228228
) {
229229
if (isUndefined(param)) {
230-
throw new UndefinedDependencyException(wrapper.name, dependencyContext, module);
230+
throw new UndefinedDependencyException(
231+
wrapper.name,
232+
dependencyContext,
233+
module,
234+
);
231235
}
232236
const token = this.resolveParamToken(wrapper, param);
233237
return this.resolveComponentInstance<T>(
@@ -293,7 +297,11 @@ export class Injector {
293297
dependencyContext.name,
294298
);
295299
if (isNil(instanceWrapper)) {
296-
throw new UnknownDependenciesException(wrapper.name, dependencyContext, module);
300+
throw new UnknownDependenciesException(
301+
wrapper.name,
302+
dependencyContext,
303+
module,
304+
);
297305
}
298306
return instanceWrapper;
299307
}
@@ -401,10 +409,9 @@ export class Injector {
401409
): Promise<T> {
402410
const { metatype, inject } = wrapper;
403411
if (isNil(inject)) {
404-
targetMetatype.instance = Object.assign(
405-
targetMetatype.instance,
406-
new metatype(...instances),
407-
);
412+
targetMetatype.instance = wrapper.forwardRef
413+
? Object.assign(targetMetatype.instance, new metatype(...instances))
414+
: new metatype(...instances);
408415
} else {
409416
const factoryResult = ((targetMetatype.metatype as any) as Function)(
410417
...instances,

packages/core/test/injector/injector.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('Injector', () => {
6969
) as InstanceWrapper<MainTest>;
7070

7171
expect(instance.depOne).instanceof(DependencyOne);
72-
expect(instance.depTwo).instanceof(DependencyOne);
72+
expect(instance.depTwo).instanceof(DependencyTwo);
7373
expect(instance).instanceof(MainTest);
7474
});
7575

0 commit comments

Comments
 (0)