| @@ -15,17 +15,17 let nextId = 1; | |||||
| 15 | * tracks services with `context` activation type. |
|
15 | * tracks services with `context` activation type. | |
| 16 | */ |
|
16 | */ | |
| 17 | export class ActivationContext<S extends object> { |
|
17 | export class ActivationContext<S extends object> { | |
| 18 |
private _cache |
|
18 | private readonly _cache: Record<string, unknown>; | |
| 19 |
|
19 | |||
| 20 | private _services: Partial<RegistrationMap<S>>; |
|
20 | private readonly _services: Partial<RegistrationMap<S>>; | |
| 21 |
|
21 | |||
| 22 | private _name: string; |
|
22 | private readonly _name: string; | |
| 23 |
|
23 | |||
| 24 | private _service: Descriptor<S, unknown>; |
|
24 | private readonly _service: Descriptor<S, unknown>; | |
| 25 |
|
25 | |||
| 26 | private readonly _containerLifetimeManager: LifetimeContainer; |
|
26 | private readonly _containerLifetimeManager: LifetimeContainer; | |
| 27 |
|
27 | |||
| 28 | private _parent: ActivationContext<S> | undefined; |
|
28 | private readonly _parent: ActivationContext<S> | undefined; | |
| 29 |
|
29 | |||
| 30 | /** Creates a new activation context with the specified parameters. |
|
30 | /** Creates a new activation context with the specified parameters. | |
| 31 | * @param containerLifetimeManager the container which starts the activation process |
|
31 | * @param containerLifetimeManager the container which starts the activation process | |
| @@ -35,10 +35,10 export class ActivationContext<S extends | |||||
| 35 | * @param service the service to activate, this parameter is used for the |
|
35 | * @param service the service to activate, this parameter is used for the | |
| 36 | * debug purpose. |
|
36 | * debug purpose. | |
| 37 | */ |
|
37 | */ | |
| 38 | constructor(containerLifetimeManager: LifetimeContainer, services: Partial<RegistrationMap<S>>, name: string, service: Descriptor<S, unknown>) { |
|
38 | constructor(containerLifetimeManager: LifetimeContainer, services: Partial<RegistrationMap<S>>, name: string, service: Descriptor<S, unknown>, cache = {}) { | |
| 39 | this._name = name; |
|
39 | this._name = name; | |
| 40 | this._service = service; |
|
40 | this._service = service; | |
| 41 |
this._cache = |
|
41 | this._cache = cache; | |
| 42 | this._services = services; |
|
42 | this._services = services; | |
| 43 | this._containerLifetimeManager = containerLifetimeManager; |
|
43 | this._containerLifetimeManager = containerLifetimeManager; | |
| 44 | } |
|
44 | } | |
| @@ -126,19 +126,13 export class ActivationContext<S extends | |||||
| 126 | stack; |
|
126 | stack; | |
| 127 | } |
|
127 | } | |
| 128 |
|
128 | |||
| 129 |
private enter(service: Descriptor<S, unknown>, name: string) |
|
129 | private enter(service: Descriptor<S, unknown>, name: string) { | |
| 130 | const clone = Object.create(this) as this; |
|
130 | return new ActivationContext( | |
| 131 | clone._name = name; |
|
131 | this._containerLifetimeManager, | |
| 132 |
|
|
132 | Object.create(this._services) as typeof this._services, | |
| 133 | clone._parent = this; |
|
133 | name, | |
| 134 |
|
|
134 | service, | |
| 135 | return clone; |
|
135 | this._cache | |
| 136 | } |
|
136 | ); | |
| 137 |
|
||||
| 138 | /** Creates a clone for the current context, used to protect it from modifications */ |
|
|||
| 139 | clone(): this { |
|
|||
| 140 | const clone = Object.create(this) as this; |
|
|||
| 141 | clone._services = Object.create(this._services) as typeof this._services; |
|
|||
| 142 | return clone; |
|
|||
| 143 | } |
|
137 | } | |
| 144 | } |
|
138 | } | |
General Comments 0
You need to be logged in to leave comments.
Login now
