๐ค ๋ฌธ์ ์ํฉ
channel.modulet.tsํ์ผ์์ event.module.tsํ์ผ์ ๋ค์ด์๋ EventGateway๋ผ๋ ํ์ผ์ ์ฌ์ฉํ๊ณ ์ถ์ ์ํฉ์ด๋ผ๊ณ ํ์.
nestjs๋ ๋ชจ๋๋ผ๋ฆฌ์ ์ํธ์์ฉ์ ํตํด ๋์ํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค. ๋ฐ๋ผ์ ๋ชจ๋๋ค์ฌ์ด์ ์ฐ๊ฒฐ์ ์์ผ์ค์ผํ๋ค.
์ผ๋จ ํ์ผ์ ์ฝ๋๋ฅผ ๋ณด์.
channels.module.ts
@Module({
imports: [],
controllers: [ChannelsController],
providers: [ChannelsService],
})
export class ChannelsModule {}
event.module.ts
import { Module } from '@nestjs/common';
import { EventGateway } from './event.gateway';
@Module({
providers: [EventGateway],
exports: [],
})
export class EventModule {}
์ ๋ ํ์ผ์ ๊ฐ์ง๊ณ ๊ฐ์ฅ ์์์ ์ ์ํ๋ ๋ฌธ์ ์ํฉ์ ๋ํด์ ์ฐ๊ฒฐํด๋ด์ผํ๋ค.
์ฐ์ event.module.ts๋ฅผ ๋ณด์ ์ดํ์ผ์ ๋ณด๋ฉด EventGateway ํ์ผ์ ์์กด์ฑ ์ฃผ์
ํ๊ณ ์๋ค. ๋ฐ๋ผ์ ์ฐ๋ฆฌ๋ event.modules.tsํ์ผ ํด๋์ค์ธ EventModule์ channels.module.ts๋ก ์์กด์ฑ ์ฃผ์
ํ๋ฉด ๋๋ค๋ผ๊ณ ์๊ฐํ๋ฉด๋๋ค.
!!์ฌ๊ธฐ์ ์ ๊น ๐
๊ทธ๋ฅ channels.module.ts ํ์ผ์์๋ค๊ฐ EventGatewayํ์ผ์ ๋ฐ๋ก providers์ ๋ฃ์ผ๋ฉด ๋๋๊ฑฐ ์๋๋?๋ผ๊ณ ๋ฐ๋ฌธํ ์๋ ์๋ค.
๋ง๋ค. EventGateway๋ฅผ ๋ฐ๋ก channels.module.ts์์ ๋ฃ์ด๋ ์ฝ๋์์ ๋ฌธ์ ๋ ์๋ค ๊ทธ๋ฌ๋ EventGatewayํ์ผ ์์ฒด๋ฅผ ๋ฃ๊ฒ๋๋ฉด, ๊ณ์ํด์ ๊ฐ์ฒด๊ฐ ์ธ์คํด์คํ ๋์ด ๋ฉ๋ชจ๋ฆฌ์ ์์ด๊ฒ๋๋ค. ๊ทธ๋ ๊ฒ๋๋ฉด ๋ถํ์ํ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์์นํ๊ฒ๋๋๊ฒ์ด๋ค. ๋ฐ๋ผ์ ์ต์ด์ event.module.ts์ด ์ด๊ธฐํ๋ฐ ์์ฑ์ด ๋ ๋์์ฑํ๋ event.module.ts๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํจ์จ์ ์ผ๋ก ์ฌ์ฉํ ์ ์๋ค.
channels.module.ts
@Module({
imports: [EventModule],
controllers: [ChannelsController],
providers: [ChannelsService],
})
export class ChannelsModule {}
event.module.ts
@Module({
providers: [EventGateway],
exports: [EventGateway] //channels.module.tsํ์ผ์์์ ๊ฐ์ด EventModule์ importํ๊ณ EventModule์์ EventGateWayํ์ผ์ ์ฌ์ฉํ๋ ค๊ณ ํ๋ค๋ฉด event.module.tsํ์ผ์์ export๋ ํจ๊ป ๋ฃ์ด์ค์ผํ๋ค.,
})
export class EventModule {}