fix(server): avoid repeatly register providers (#5265)

This commit is contained in:
liuyi
2023-12-13 02:12:37 +00:00
parent f4a52c031f
commit 797cd5c6eb
12 changed files with 34 additions and 53 deletions
@@ -1,38 +1,12 @@
import { DynamicModule } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { DocHistoryManager } from './history';
import { DocManager } from './manager';
export class DocModule {
/**
* @param automation whether enable update merging automation logic
*/
private static defModule(automation = true): DynamicModule {
return {
module: DocModule,
providers: [
{
provide: 'DOC_MANAGER_AUTOMATION',
useValue: automation,
},
DocManager,
DocHistoryManager,
],
exports: [DocManager, DocHistoryManager],
};
}
static forRoot() {
return this.defModule();
}
static forSync(): DynamicModule {
return this.defModule(false);
}
static forFeature(): DynamicModule {
return this.defModule(false);
}
}
@Module({
providers: [DocManager, DocHistoryManager],
exports: [DocManager, DocHistoryManager],
})
export class DocModule {}
export { DocHistoryManager, DocManager };
@@ -1,5 +1,4 @@
import {
Inject,
Injectable,
Logger,
OnModuleDestroy,
@@ -97,8 +96,6 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
private busy = false;
constructor(
@Inject('DOC_MANAGER_AUTOMATION')
private readonly automation: boolean,
private readonly db: PrismaService,
private readonly config: Config,
private readonly cache: Cache,
@@ -106,7 +103,7 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
) {}
onModuleInit() {
if (this.automation) {
if (this.config.doc.manager.enableUpdateAutoMerging) {
this.logger.log('Use Database');
this.setup();
}