UNPKG

@inversifyjs/container

Version:

InversifyJs container

25 lines 1.16 kB
import { InversifyContainerError } from '../../error/models/InversifyContainerError.js'; import { InversifyContainerErrorKind } from '../../error/models/InversifyContainerErrorKind.js'; export class SnapshotManager { #serviceReferenceManager; #snapshots; constructor(serviceReferenceManager) { this.#serviceReferenceManager = serviceReferenceManager; this.#snapshots = []; } restore() { const snapshot = this.#snapshots.pop(); if (snapshot === undefined) { throw new InversifyContainerError(InversifyContainerErrorKind.invalidOperation, 'No snapshot available to restore'); } this.#serviceReferenceManager.reset(snapshot.activationService, snapshot.bindingService, snapshot.deactivationService); } snapshot() { this.#snapshots.push({ activationService: this.#serviceReferenceManager.activationService.clone(), bindingService: this.#serviceReferenceManager.bindingService.clone(), deactivationService: this.#serviceReferenceManager.deactivationService.clone(), }); } } //# sourceMappingURL=SnapshotManager.js.map