繁体   English   中英

为什么nest没有解决ZCCADCDEDB567ABAE643E15DCF0974E503Z Model的依赖关系?

[英]Why is nest not resolving the Mongoose Model Dependency?

我正在尝试使用@nest/config package 从.env 导入MongoDB URI,但我遇到了另一个错误,我的@InjectModel 一直失败,我不知道为什么。 根据错误,这是一个依赖问题。 我在下面包含了有问题的文件。

app.module.ts

import { CacheModule, Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { AuthController } from './Auth/auth.controller';
import { AuthService } from './Auth/auth.service';
import { CarSearchController } from './CarSearch/carSearch.controller';
import { CarSearchService } from './CarSearch/carSearch.service';
import configuration from './config/configuration';

@Module({
    imports: [
        ConfigModule.forRoot({
            isGlobal: true,
            load: [configuration]
        }),

        MongooseModule.forRootAsync({
            inject: [ConfigService],
            useFactory: async (config: ConfigService) => ({
                uri: config.get<string>('database.uri') // Loaded from .ENV
            })
        }),

        CacheModule.register({
            isGlobal: true
        })
    ],
    controllers: [AuthController, CarSearchController],
    providers: [AuthService, CarSearchService]
})
export class AppModule {}

carSearch.module.ts

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { AuthModule } from 'src/Auth/auth.module';
import { IndeTrans, IndeTransSchema } from 'src/schema/IndeTrans.schema';
import { CarSearchController } from './carSearch.controller';
import { CarSearchService } from './carSearch.service';

@Module({
    imports: [
        AuthModule,
        ConfigModule,
        MongooseModule.forFeature([
            { name: IndeTrans.name, schema: IndeTransSchema }
        ])
    ],
    controllers: [CarSearchController],
    providers: [CarSearchService]
})
export class CarSearchModule {}

carSearch.service.ts

import {
    CACHE_MANAGER,
    HttpException,
    Inject,
    Injectable
} from '@nestjs/common';
import 'dotenv/config';
import axios from 'axios';
import { Cache } from 'cache-manager';
import { AuthService } from 'src/Auth/auth.service';
import moment from 'moment';
import { ConfigService } from '@nestjs/config';
import { validateCarSearchResponse } from './validation/mmt_response-validation';
import { validateJoi } from './validation/validateJoi';
import { Model } from 'mongoose';
import { IndeTrans, IndeTransDocument } from 'src/schema/IndeTrans.schema';
import { InjectModel } from '@nestjs/mongoose';

@Injectable()
export class CarSearchService {

    constructor(
        @Inject(CACHE_MANAGER) private cacheManager: Cache,
        private readonly authModel: AuthService,
        @InjectModel(IndeTrans.name)
        private IndeTransModel: Model<IndeTransDocument>,
        private configService: ConfigService
    ) {}

错误

Error: Nest can't resolve dependencies of the CarSearchService (CACHE_MANAGER, AuthService, ?, ConfigService). Please make sure that the argument IndeTransModel at index [2] is available in the AppModule context.

Potential solutions:
- If IndeTransModel is a provider, is it part of the current AppModule?
- If IndeTransModel is exported from a separate @Module, is that module imported within AppModule?
  @Module({
    imports: [ /* the Module containing IndeTransModel */ ]
  })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM