Skip to content

Commit 5fb5ffc

Browse files
authored
Merge pull request #43 from asvetliakov/master
Improve applying property handlers
2 parents 43ebb5d + 685bf50 commit 5fb5ffc

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/ContainerInstance.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class ContainerInstance {
2020
* Container instance id.
2121
*/
2222
id: any;
23-
23+
2424
// -------------------------------------------------------------------------
2525
// Private Properties
2626
// -------------------------------------------------------------------------
@@ -37,7 +37,7 @@ export class ContainerInstance {
3737
constructor(id: any) {
3838
this.id = id;
3939
}
40-
40+
4141
// -------------------------------------------------------------------------
4242
// Public Methods
4343
// -------------------------------------------------------------------------
@@ -270,7 +270,7 @@ export class ContainerInstance {
270270
}
271271

272272
if (type)
273-
this.applyPropertyHandlers(type);
273+
this.applyPropertyHandlers(type, service.value);
274274

275275
return service.value;
276276
}
@@ -302,18 +302,13 @@ export class ContainerInstance {
302302
/**
303303
* Applies all registered handlers on a given target class.
304304
*/
305-
private applyPropertyHandlers(target: Function) {
305+
private applyPropertyHandlers(target: Function, instance: { [key: string]: any }) {
306306
Container.handlers.forEach(handler => {
307-
if (handler.index) return;
307+
if (typeof handler.index === "number") return;
308308
if (handler.object.constructor !== target && !(target.prototype instanceof handler.object.constructor))
309309
return;
310310

311-
Object.defineProperty(handler.object, handler.propertyName, {
312-
enumerable: true,
313-
writable: true,
314-
configurable: true,
315-
value: handler.value(this)
316-
});
311+
instance[handler.propertyName] = handler.value(this);
317312
});
318313
}
319314

0 commit comments

Comments
 (0)