I am learning NestJS and I was reading the documentation but couldn't find an answer for this question.
I have my infrastructure module:
@Module({
imports: [DatabaseModule],
controllers: [],
providers: [
ConfigService,
{
provide: 'RequestClient',
useClass: AxiosRequestClient
},
{
provide: 'FileStorage',
useClass: S3FileStorage
}
],
exports: ['RequestClient', 'FileStorage', DatabaseModule]
})
export class InfrastructureModule {}
I import this into my AppModule
:
@Module({
imports: [
ConfigModule.forRoot({
load: [filesystemConfig, awsConfig, databaseConfig],
isGlobal: true,
cache: true
}),
InfrastructureModule,
PhysicianModule,
PatientModule,
RemsModule
],
controllers: [],
providers: [ApiResponseInterceptor]
})
export class AppModule {}
Will the InfrastructureModule
exports be available to PatientModule
or do I need to import the InfrastructureModule
to PatientModule
?
Currently when I am trying to inject like this:
export default class PatientMedicalRecordFileRepository implements IPatientMedicalRecordFileRepository {
private readonly tempPath: string
private readonly s3Path: string = 'private/patients'
private readonly cloudfrontBaseUrl: string
constructor(
private readonly configService: ConfigService,
@Inject('FileStorage') private readonly fileStorage: IFileStorageService
) {
I get the error:
ERROR [ExceptionHandler] Nest can't resolve dependencies of the PatientMedicalRecordFileRepository (ConfigService, ?). Please make sure that the argument FileStorage at index [1] is available in the RemsModule context.
At the root level of NestJS, you have the AppModule
. This is the module where you need to register all modules that you want to use in your app. These includes any external modules (like HttpModule
), and your own modules (like InfrastructureModule
).
NestJS will use this information to build an application graph, where it shall go through all modules listed in AppModule
and try to initialise those modules.
If you need to use InfrastructureModule
in PatientModule
, then you will have to import it in PatientModule
, like:
@Module({
imports: [
InfrastructureModule,
],
...
})
export class PatientModule {}
Now, within PatientModule
, you can use any services from InfrastructureModule
that are exported.
Which means, any of these:
exports: ['RequestClient', 'FileStorage', DatabaseModule]