diff --git a/.changeset/slimy-otters-sparkle.md b/.changeset/slimy-otters-sparkle.md new file mode 100644 index 00000000..c2696453 --- /dev/null +++ b/.changeset/slimy-otters-sparkle.md @@ -0,0 +1,5 @@ +--- +"@inversifyjs/container": minor +--- + +Updated `ContainerModule.load` to support sync load functions diff --git a/packages/container/libraries/container/src/container/models/ContainerModule.spec.ts b/packages/container/libraries/container/src/container/models/ContainerModule.spec.ts index 70e06db7..baf73928 100644 --- a/packages/container/libraries/container/src/container/models/ContainerModule.spec.ts +++ b/packages/container/libraries/container/src/container/models/ContainerModule.spec.ts @@ -36,14 +36,23 @@ describe(ContainerModule.name, () => { describe('.load', () => { describe('when called', () => { + let optionsFixture: ContainerModuleLoadOptions; + let result: unknown; - beforeAll(() => { - result = new ContainerModule(loadMock).load; + beforeAll(async () => { + optionsFixture = Symbol() as unknown as ContainerModuleLoadOptions; + + result = await new ContainerModule(loadMock).load(optionsFixture); + }); + + it('should call load()', () => { + expect(loadMock).toHaveBeenCalledTimes(1); + expect(loadMock).toHaveBeenCalledWith(optionsFixture); }); it('should return expected value', () => { - expect(result).toBe(loadMock); + expect(result).toBeUndefined(); }); }); }); diff --git a/packages/container/libraries/container/src/container/models/ContainerModule.ts b/packages/container/libraries/container/src/container/models/ContainerModule.ts index efa32e46..8c3d3518 100644 --- a/packages/container/libraries/container/src/container/models/ContainerModule.ts +++ b/packages/container/libraries/container/src/container/models/ContainerModule.ts @@ -24,9 +24,11 @@ export interface ContainerModuleLoadOptions { export class ContainerModule { readonly #id: number; - readonly #load: (options: ContainerModuleLoadOptions) => Promise; + readonly #load: (options: ContainerModuleLoadOptions) => void | Promise; - constructor(load: (options: ContainerModuleLoadOptions) => Promise) { + constructor( + load: (options: ContainerModuleLoadOptions) => void | Promise, + ) { this.#id = getContainerModuleId(); this.#load = load; } @@ -35,7 +37,7 @@ export class ContainerModule { return this.#id; } - public get load(): (options: ContainerModuleLoadOptions) => Promise { - return this.#load; + public async load(options: ContainerModuleLoadOptions): Promise { + await this.#load(options); } }