Skip to content

Commit d1ad943

Browse files
feature() support abstract classes in nest ctx
1 parent 69fb434 commit d1ad943

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

packages/core/injector/container-scanner.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Type } from '@nestjs/common';
2+
import { Abstract } from '@nestjs/common/interfaces';
23
import { isFunction } from '@nestjs/common/utils/shared.utils';
34
import { UnknownElementException } from '../errors/exceptions/unknown-element.exception';
45
import { InstanceWrapper, NestContainer } from './container';
@@ -10,7 +11,7 @@ export class ContainerScanner {
1011
constructor(private readonly container: NestContainer) {}
1112

1213
public find<TInput = any, TResult = TInput>(
13-
typeOrToken: Type<TInput> | string | symbol,
14+
typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol,
1415
): TResult {
1516
this.initFlatContainer();
1617
return this.findInstanceByPrototypeOrToken<TInput, TResult>(
@@ -20,7 +21,7 @@ export class ContainerScanner {
2021
}
2122

2223
public findInstanceByPrototypeOrToken<TInput = any, TResult = TInput>(
23-
metatypeOrToken: Type<TInput> | string | symbol,
24+
metatypeOrToken: Type<TInput> | Abstract<TInput> | string | symbol,
2425
contextModule: Partial<Module>,
2526
): TResult {
2627
const dependencies = new Map([

packages/core/nest-application-context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
OnModuleDestroy,
77
OnModuleInit,
88
} from '@nestjs/common';
9+
import { Abstract } from '@nestjs/common/interfaces';
910
import { Type } from '@nestjs/common/interfaces/type.interface';
1011
import { isNil, isUndefined } from '@nestjs/common/utils/shared.utils';
1112
import iterate from 'iterare';
@@ -46,7 +47,7 @@ export class NestApplicationContext implements INestApplicationContext {
4647
}
4748

4849
public get<TInput = any, TResult = TInput>(
49-
typeOrToken: Type<TInput> | string | symbol,
50+
typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol,
5051
options: { strict: boolean } = { strict: false },
5152
): TResult {
5253
if (!(options && options.strict)) {
@@ -170,7 +171,7 @@ export class NestApplicationContext implements INestApplicationContext {
170171
}
171172

172173
protected find<TInput = any, TResult = TInput>(
173-
typeOrToken: Type<TInput> | string | symbol,
174+
typeOrToken: Type<TInput> | Abstract<TInput> | string | symbol,
174175
): TResult {
175176
return this.containerScanner.find<TInput, TResult>(typeOrToken);
176177
}

0 commit comments

Comments
 (0)