我试图弄清楚为什么出现以下错误:
嵌套无法解析UniqueInteractionsService(?)的依赖项。 请确保索引[0]的参数依赖性为 在SharedModule上下文中可用。
我的课程:
sharedModule.ts:
import {Module, Global} from '@nestjs/common';
import {InteractionsService} from "./elasticsearch/interactionsService";
import {UniqueInteractionsService} from "./elasticsearch/uniqueInteractionsService";
import {EsProvider} from "./elasticsearch/esProvider";
@Global()
@Module({
exports: [InteractionsService, UniqueInteractionsService],
providers: [EsProvider, InteractionsService, UniqueInteractionsService]
})
export class SharedModule {
}
interacionsService.ts:
import {ESService} from "./ESService";
import {Injectable, Inject} from '@nestjs/common';
@Injectable()
export class InteractionsService{
constructor(@Inject(ESService) private readonly esService: ESService) {}
// more stuff
}
uniqueInteractionsService.ts:
import {ESService} from "./ESService";
import {Injectable, Inject} from '@nestjs/common';
@Injectable()
export class UniqueInteractionsService{
constructor(@Inject(ESService) private readonly esService: ESService) {}
// more stuff
}
esProvider.ts:
import {ESService} from "./esService";
export const EsProvider = {
provide: ESService,
useFactory: async () => {
const esService = new ESService();
await esService.init();
return esService;
}
};
答案 0 :(得分:0)
您正在从SharedModule导出UniqueInteractionsService。在目标模块中,您需要导入此SharedModule,然后可以通过依赖项注入在属于TargetModule的targetService中使用UniqueInteractionsService。
示例:
.content-wrapper{
min-height: 100% !important;
}