Backend_DevOps

NestJS Dynamic Module 주의점

2025-12-271 min read

NestJS Dynamic Module 주의점

export const databaseProviders = [
	{
		provide: MysqlDatasourceKey,
		inject: [ConfigService, MysqlConfigService],
		useFactory: async (
			configService: ConfigService,
			databaseConfigService: MysqlConfigService,
		) => {
			const dataSource = new DataSource(
				databaseConfigService.getTypeormConfig(),
			)
			return dataSource.initialize()
		},
	},
]

위와 같은 상황에서 useFactory에 인자에는 무조건 inject배열의 순서대로 인스턴스가 들어온다

  • 참고
    • MySqlConfigServiceConfigService에 의존성이 있다.
Share

Related Articles

Comments

이 블로그는 제가 알고 있는 것들을 잊지 않기 위해 기록하는 공간입니다.
직접 작성한 글도 있고, AI의 도움을 받아 정리한 글도 있습니다.
정확하지 않은 내용이 있을 수 있으니 참고용으로 봐주세요.

© 2026 Seogyu Kim