【发布时间】:2019-09-14 07:47:51
【问题描述】:
无法弄清楚我的代码有什么问题。查看错误描述的内容;我觉得没问题。
运行npm start 控制台说:
Nest 无法解析 DescribeService 的依赖关系 (UrlsAfipService,WsaaService,?)。请确保参数 at index [2] 在 ApiModule 上下文中可用。
描述服务
import { Injectable } from '@nestjs/common';
import { UrlsAfipService } from './urls-afip.service'
import { WsaaService } from './wsaa.service'
import * as soap from 'soap';
@Injectable()
export class DescribeService {
constructor (
private readonly urlsAfipService: UrlsAfipService,
private readonly wsaaService: WsaaService,
private clients: object
) {}
private createClientForService(service: string): Promise<any> {
return new Promise((resolve, reject) => {
if (this.clients[service]) {
resolve(this.clients[service])
} else {
soap.createClient(this.urlsAfipService.getService(service), (err, client) => {
if (err && !client) {
reject(err)
} else {
this.clients[service] = client;
resolve(client);
}
})
}
})
}
describe(service) {
this.wsaaService.generateToken(service).then((tokens) => {
this.createClientForService(service).then((client) => {
return client.describe()
});
}).catch((err) => {
return err.message
})
}
}
ApiModule
import { Module } from '@nestjs/common';
import { ConfigModule } from '../config/config.module';
import { ApiController } from './api.controller';
import { UrlsAfipService } from './urls-afip.service'
import { WsaaService } from './wsaa.service'
import { DescribeService } from './describe.service';
@Module({
controllers: [ApiController],
providers: [UrlsAfipService, WsaaService, DescribeService],
imports: [ConfigModule]
})
export class ApiModule {}
【问题讨论】:
标签: javascript node.js typescript dependency-injection nestjs