add new module

This commit is contained in:
2025-05-18 21:06:51 +08:00
parent c196b00708
commit fd6631aba6
10 changed files with 433 additions and 140 deletions
@@ -1,53 +0,0 @@
import { DynamicModule, Global, Injectable, Module } from '@nestjs/common';
import { get } from 'lodash';
import { AppController } from '@/app.controller';
import { AppService } from '@/app.service';
import { ContentModule } from '@/modules/content/content.module';
const config: Record<string, any> = {
name: 'ray',
};
@Injectable()
export class ConfigService {
protected config: RecordAny = {};
constructor(data: RecordAny) {
this.config = data;
}
get<T>(key: string, defaultValue?: T): T | undefined {
return get(config, key, defaultValue);
}
}
@Global()
@Module({
providers: [ConfigService],
exports: [ConfigService],
})
export class CoreModule {
static forRoot(options: { config: RecordAny }): DynamicModule {
return {
module: CoreModule,
global: true,
providers: [
{
provide: ConfigService,
useFactory() {
return new ConfigService(options.config);
},
},
],
exports: [ConfigService],
};
}
}
@Module({
imports: [ContentModule, CoreModule.forRoot({ config: { name: 'ray' } })],
providers: [AppService],
controllers: [AppController],
})
export class AppModule {}