Asynchronous providers

Asynchronous providers

์ผ๋ถ€ ๋น„๋™๊ธฐ ์ž‘์—…์ด ์™„๋ฃŒ ๋  ๋•Œ๊นŒ์ง€ (์˜ˆ: ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€์˜ ์—ฐ๊ฒฐ์ด ์„ค์ • ๋  ๋•Œ๊นŒ์ง€) ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘์„ ์ง€์—ฐํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ ๋น„๋™๊ธฐ ๊ณต๊ธ‰์ž ์‚ฌ์šฉ์„ ๊ณ ๋ คํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋น„๋™๊ธฐ ๊ณต๊ธ‰์ž๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด useFactory๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ํŒฉํ† ๋ฆฌ๋Š” Promise๋ฅผ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค (๋”ฐ๋ผ์„œ async ๊ธฐ๋Šฅ๋„ ์ ํ•ฉํ•ฉ๋‹ˆ๋‹ค).

{
  provide: 'ASYNC_CONNECTION',
  useFactory: async () => {
    const connection = await createConnection(options);
    return connection;
  },
}

info ํžŒํŠธ ์‚ฌ์šฉ์ž ์ •์˜ ์ œ๊ณต์ž ๊ตฌ๋ฌธ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด์‹ญ์‹œ์˜ค ์—ฌ๊ธฐ.

Injection

๋น„๋™๊ธฐ ํ”„๋กœ๋ฐ”์ด๋”๋Š” ํ† ํฐ (์œ„์˜ ๊ฒฝ์šฐ ASYNC_CONNECTIONํ† ํฐ)์— ์˜ํ•ด ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์— ๊ฐ„๋‹จํžˆ ์ฃผ์ž…๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋น„๋™๊ธฐ ๊ณต๊ธ‰์ž๊ฐ€ ์ด๋ฏธ ํ•ด๊ฒฐ๋˜๋ฉด ๋น„๋™๊ธฐ ๊ณต๊ธ‰์ž์— ์ข…์†๋œ ๊ฐ ํด๋ž˜์Šค๊ฐ€ ์ธ์Šคํ„ด์Šคํ™”๋ฉ๋‹ˆ๋‹ค.

์œ„์˜ ์˜ˆ๋Š” ๋ฐ๋ชจ์šฉ์ž…๋‹ˆ๋‹ค. ๋” ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ์›ํ•œ๋‹ค๋ฉด ์—ฌ๊ธฐ ์ฐธ์กฐ.

Last updated