Skip to content

Commit

Permalink
feat: add conflictCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Mar 1, 2021
1 parent 8d0227d commit a892223
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/core/src/baseFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,17 @@ export abstract class BaseFramework<
/**
* initialize container
*/
this.applicationContext = new MidwayContainer(this.baseDir, undefined);
this.applicationContext.disableConflictCheck =
options.disableConflictCheck || true;
this.applicationContext.registerObject('baseDir', this.baseDir);
this.applicationContext.registerObject('appDir', this.appDir);
this.applicationContext.registerObject('isTsMode', this.isTsMode);

if (MidwayContainer.parentApplicationContext) {
this.applicationContext = new MidwayContainer(this.baseDir, undefined);
this.applicationContext.parent = MidwayContainer.parentApplicationContext;
} else {
this.applicationContext = new MidwayContainer(this.baseDir, undefined);
this.applicationContext.registerObject('baseDir', this.baseDir);
this.applicationContext.registerObject('appDir', this.appDir);
this.applicationContext.registerObject('isTsMode', this.isTsMode);
}

/**
* initialize base information
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/context/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ export class ContainerConfiguration implements IContainerConfiguration {
configurationOptions.directoryResolveFilter
);
}
if (configurationOptions.conflictCheck) {
this.container.disableConflictCheck = !configurationOptions.conflictCheck;
}
this.addImports(configurationOptions.imports, baseDir);
this.addImportObjects(configurationOptions.importObjects);
this.addImportConfigs(configurationOptions.importConfigs, baseDir);
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/context/midwayContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ let containerIdx = 0;

export function clearContainerCache() {
MidwayContainer.parentDefinitionMetadata = null;
MidwayContainer.parentApplicationContext = null;
}

export class MidwayContainer
Expand All @@ -94,10 +95,17 @@ export class MidwayContainer
* 单个进程中上一次的 applicationContext 的 registry
*/
static parentDefinitionMetadata: Map<string, IObjectDefinitionMetadata[]>;
/**
* 单进程中上一次的 applicationContext
*/
static parentApplicationContext: IMidwayContainer;

constructor(baseDir: string = process.cwd(), parent?: IApplicationContext) {
super(baseDir, parent);
this.id = '00' + this.createContainerIdx();
if (!MidwayContainer.parentApplicationContext) {
MidwayContainer.parentApplicationContext = this;
}
}

protected createContainerIdx() {
Expand Down
7 changes: 7 additions & 0 deletions packages/decorator/src/annotation/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ export interface ResolveFilter {
filter: (module, filter, bindModule) => any;
}

export enum ApplicationScopeEnum {
GLOBAL = 'global',
CONTAINER = 'container',
}

export interface InjectionConfigurationOptions {
imports?: Array<string | IComponentInfo | { Configuration: any }>;
importObjects?: Record<string, unknown>;
importConfigs?: string[];
namespace?: string;
directoryResolveFilter?: ResolveFilter[];
applicationContextScope?: ApplicationScopeEnum,
conflictCheck?: boolean;
}

export function Configuration(
Expand Down

0 comments on commit a892223

Please sign in to comment.