import { IApplication } from '@/domain/IApplication'; import { AsyncLazy } from '@/infrastructure/Threading/AsyncLazy'; import { IApplicationFactory } from './IApplicationFactory'; import { parseApplication } from './Parser/ApplicationParser'; export type ApplicationGetter = () => IApplication; const ApplicationGetter: ApplicationGetter = parseApplication; export class ApplicationFactory implements IApplicationFactory { public static readonly Current: IApplicationFactory = new ApplicationFactory(ApplicationGetter); private readonly getter: AsyncLazy; protected constructor(costlyGetter: ApplicationGetter) { if (!costlyGetter) { throw new Error('undefined getter'); } this.getter = new AsyncLazy(() => Promise.resolve(costlyGetter())); } public getApp(): Promise { return this.getter.getValue(); } }