diff --git a/lib/common/config/config.init-fn.ts b/lib/common/config/config.init-fn.ts index 7141cf7..15f4b7e 100644 --- a/lib/common/config/config.init-fn.ts +++ b/lib/common/config/config.init-fn.ts @@ -28,11 +28,12 @@ import { ConfigService } from "./config.service"; * This function used for initialize config store */ export const InitConfig = async () => { - const app = await NestFactory.createApplicationContext(ConfigModule); + const mod = ConfigModule.forInitializer(); + const app = await NestFactory.createApplicationContext(mod); await app.init(); const logger: Logger = app.select(LogModule).get(LOGGER); EnvLoader.loadEnvironment(logger); - const configService = app.select(ConfigModule).get(ConfigService); + const configService = app.select(mod).get(ConfigService); const genCnfDir = `${process.cwd()}/${process.env.CONFIG_SRC_DIR}`; await configService.initWithPropertiesFiles(genCnfDir); await app.close(); diff --git a/lib/common/config/config.module.ts b/lib/common/config/config.module.ts index c1b486f..c44b152 100644 --- a/lib/common/config/config.module.ts +++ b/lib/common/config/config.module.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Module } from "@nestjs/common"; +import { DynamicModule, Module } from "@nestjs/common"; import { ConfigService } from "./config.service"; import { LogModule } from "../../shared/modules/log/log.module"; import { CacheModule } from "../../shared/modules/cache/cache.module"; @@ -24,10 +24,24 @@ import { ConfigController } from "./config.controller"; /** * Module for work with system configuration. */ -@Module({ - imports: [LogModule, CacheModule, UserModule.forRoot()], - controllers: [ConfigController], - providers: [ConfigService], - exports: [ConfigService], -}) -export class ConfigModule {} +@Module({}) +export class ConfigModule { + static forRoot(): DynamicModule { + return { + module: ConfigModule, + imports: [LogModule, CacheModule, UserModule.forRoot()], + controllers: [ConfigController], + providers: [ConfigService], + exports: [ConfigService], + }; + } + + static forInitializer(): DynamicModule { + return { + module: ConfigModule, + imports: [LogModule, CacheModule], + providers: [ConfigService], + exports: [ConfigService], + }; + } +}