Created
November 6, 2023 19:36
-
-
Save alexbridge/4d7397d60a184d5d2073410d11dc5e8d to your computer and use it in GitHub Desktop.
Nestjs useFactory example with inject and ConfigService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module({ | |
providers: [ | |
{ | |
provide: MyApiService, | |
useFactory: (configService: ConfigService) => { | |
return new MyApiService( | |
configService.getOrThrow('MY_BASE_URL'), | |
configService.getOrThrow('MY_USER'), | |
configService.getOrThrow('MY_PASSWORD') | |
); | |
}, | |
inject: [ConfigService], | |
}, | |
], | |
exports: [MyApiService], | |
}) | |
export class MyApiModule {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment