适用于 NestJS v8、v9 和 v10
什么?
假设您想要使用由您无法控制的第 3 方库创建的同一 NestJS 提供程序的多个“版本”。
例如,当使用来自的 HttpModule模块@nestjs/axios时,我们可以使用动态模块HttpModule.register()来配置我们的 Axios 实例。该模块公开了HttpService具有此类配置的模块。但是,如果我们想要拥有许多 Axios 实例,每个实例都有自己的配置并将所有内容导入一个模块中,该怎么办?
我们无法执行以下操作,因为无法区分HttpService注册的两个提供程序,因为它们位于同一注入令牌(即类引用HttpService)下,尽管我们有该类的两个实例:
@Module({
imports: [
HttpModule.register({
baseURL: 'https://api.example.com',
}),
HttpModule.register({
baseURL: 'https://api.another.example.com',
}),
],
})
export class AppModule {
constructor