@Injectable()
export class Test1Service {
constructor(
test2Service: Test2Service
) {}
getIndex() {
console.log(111);
}
}
@Injectable()
export class Test2Service {
item;
constructor(name) {
if (name === 'blog') {
this.item = 'item1';
} else {
this.item = 'item2';
}
}
}
@Module({
controllers: [AppController],
providers: [
Test1Service,
{
provide: 'BLOG',
useValue: new Test2Service('blog'),
},
{
provide: 'ANALYTICS',
useValue: new Test2Service('analytics'),
}
],
})
export class AppModule {}
@Injectable()
export class Test1Service {
constructor(
@Inject('BLOG') public testBlog: Test2Service,
@Inject('ANALYTICS') public testAnalytics: Test2Service
) {}
getIndex() {
this.testBlog.getIndex()
this.testAnalytics.getIndex()
}
}