Skip to content

Commit

Permalink
Added freeze to ModuleFactoryLocator
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Aug 2, 2024
1 parent a090b62 commit 3f09346
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { standardCreatableFactories } from './standardCreatableFactories.ts'
* A class which encapsulates the Service Locator Pattern for Module Factories
*/
export class ModuleFactoryLocator {
private _frozen = false

constructor(protected readonly _registry: CreatableModuleRegistry = standardCreatableFactories()) {}

/**
Expand All @@ -25,6 +27,10 @@ export class ModuleFactoryLocator {
return this._registry
}

freeze() {
this._frozen = true
}

/**
* Locates a module factory that matches the supplied schema and labels
* @param schema The config schema for the module
Expand Down Expand Up @@ -57,6 +63,7 @@ export class ModuleFactoryLocator {
* @param labels The labels for the module factory
*/
register(factory: CreatableModuleFactory, labels?: Labels, primary: boolean | Schema | Schema[] = false): this {
assertEx(!this._frozen, () => 'Cannot register a module factory after the locator has been frozen')
registerCreatableModuleFactory(this._registry, factory, labels, primary)
return this
}
Expand Down

0 comments on commit 3f09346

Please sign in to comment.