# HG changeset patch # User cin # Date 2022-05-24 09:41:14 # Node ID 8a4027b4c19faa777ac3455338b1d6952ae05ca2 # Parent 154d88dba49c476908cf80d3ab322ae3a60e9960 ActivationContext removed 'clone' method, rewritten 'enter' method diff --git a/src/main/ts/ActivationContext.ts b/src/main/ts/ActivationContext.ts --- a/src/main/ts/ActivationContext.ts +++ b/src/main/ts/ActivationContext.ts @@ -15,17 +15,17 @@ let nextId = 1; * tracks services with `context` activation type. */ export class ActivationContext { - private _cache: { [K: string]: unknown }; + private readonly _cache: Record; - private _services: Partial>; + private readonly _services: Partial>; - private _name: string; + private readonly _name: string; - private _service: Descriptor; + private readonly _service: Descriptor; private readonly _containerLifetimeManager: LifetimeContainer; - private _parent: ActivationContext | undefined; + private readonly _parent: ActivationContext | undefined; /** Creates a new activation context with the specified parameters. * @param containerLifetimeManager the container which starts the activation process @@ -35,10 +35,10 @@ export class ActivationContext>, name: string, service: Descriptor) { + constructor(containerLifetimeManager: LifetimeContainer, services: Partial>, name: string, service: Descriptor, cache = {}) { this._name = name; this._service = service; - this._cache = {}; + this._cache = cache; this._services = services; this._containerLifetimeManager = containerLifetimeManager; } @@ -126,19 +126,13 @@ export class ActivationContext, name: string): this { - const clone = Object.create(this) as this; - clone._name = name; - clone._services = Object.create(this._services) as typeof this._services; - clone._parent = this; - clone._service = service; - return clone; - } - - /** Creates a clone for the current context, used to protect it from modifications */ - clone(): this { - const clone = Object.create(this) as this; - clone._services = Object.create(this._services) as typeof this._services; - return clone; + private enter(service: Descriptor, name: string) { + return new ActivationContext( + this._containerLifetimeManager, + Object.create(this._services) as typeof this._services, + name, + service, + this._cache + ); } }