-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Labels
needs triageThis issue has not been looked intoThis issue has not been looked into
Description
Bug Report
Current behavior
Dependency injector resolves dependencies using a class name instead of a class reference. It causes conflicts when two different classes share the same name.
Input Code
REPL: https://repl.it/@tooleks/CloudyRoundGnuassembler
// index.ts
import { NestFactory } from '@nestjs/core';
import { ExampleModule } from './example.module';
async function bootstrap() {
await NestFactory.createApplicationContext(ExampleModule);
}
bootstrap();
// example.module.ts
import { Inject, Module } from '@nestjs/common';
import { AService as A1Service } from './a-1.service';
import { AService as A2Service } from './a-2.service';
@Module({
providers: [A1Service, A2Service],
})
export class ExampleModule {
constructor(@Inject(A1Service) private readonly aService: A1Service) {}
onModuleInit(): void {
console.log('Expected: a-1.service.ts');
console.log(`Actual: ${this.aService.file}`);
}
}
// a-1.service.ts
import { Injectable } from '@nestjs/common';
Injectable()
export class AService {
public readonly file = 'a-1.service.ts';
}
// a-2.service.ts
import { Injectable } from '@nestjs/common';
Injectable()
export class AService {
public readonly file = 'a-2.service.ts';
}
// Output
Expected: a-1.service.ts
Actual: a-2.service.ts
Expected behavior
// Output
Expected: a-1.service.ts
Actual: a-1.service.ts
Possible Solution
Register and resolve dependencies using a class reference instead of class name as a dependency injection token.
Environment
Nest version: 7.4.4
For Tooling issues:
- Node version: 12
- Platform: Linux
Others:
N/A
UPD: Code formatting.
Metadata
Metadata
Assignees
Labels
needs triageThis issue has not been looked intoThis issue has not been looked into