Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call config service just once and store value to class property #185

Open
CllDMR opened this issue Feb 16, 2023 · 1 comment · May be fixed by #188
Open

Call config service just once and store value to class property #185

CllDMR opened this issue Feb 16, 2023 · 1 comment · May be fixed by #188
Assignees

Comments

@CllDMR
Copy link
Collaborator

CllDMR commented Feb 16, 2023

Bazı service'lerde config service'i .env değerlerini fonksiyon içerisinde çağırmış. Env değerleri backend uygulaması ilk initialize edilirken belirleniyor ve bir daha değişmiyor. Bu değerleri service'lerimizin onModuleInit lifecyle event'inde çağırıp service class'ı içerisinde private bir property'ye assign edebiliriz.

Örnek olarak Burada config service'i fonksiyon içerisinde kullanılmış.

import { Injectable, OnModuleInit } from '@nestjs/common';

...

@Injectable()
export class UserService implements OnModuleInit {
  private bcryptSecret: string;

...

  onModuleInit() {
    this.bcryptSecret = this.configService.get<string>('bcrypt.secret');
  }

Şeklinde uygulanabilir.

@CllDMR
Copy link
Collaborator Author

CllDMR commented Feb 17, 2023

@busebatman Merhabalar, bu task'ı bana assign edebilir misin ?

@CllDMR CllDMR linked a pull request Feb 18, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant