'Using ConfigService inside async provider nestjs
I want to know if it possible to inject ConfigService into module import:
import { Module } from '@nestjs/common';
import { FileService } from './file.service';
import { FileResolver } from './file.resolver';
import { FileUploadController } from './contollers/file-upload.controller';
import { S3Service } from './host/s3.service';
import { AwsSdkModule } from 'nest-aws-sdk';
import { S3, SharedIniFileCredentials } from 'aws-sdk';
@Module({
controllers: [FileUploadController],
providers: [FileService, FileResolver, S3Service],
exports: [FileService, FileResolver],
imports: [
ConfigService.forRoot(),
AwsSdkModule.forRoot({
// use config service here
// configService.get('some-value')
defaultServiceOptions: {
region: 'us-east-1',
credentials: new SharedIniFileCredentials({
profile: 'my-profile',
}),
},
services: [S3],
}),
],
})
export class StorageModule {}
is it possible to use the configService inside AwsSdkModule provider?
Solution 1:[1]
Maybe you could try
AwsSdkModule.forRootAsync({
imports: [ConfigService],
inject: [ConfigService],
useFactory: (configService: ConfigService) {
}
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DevOskar |
