Skip to content

Commit c7011a9

Browse files
committed
Fix applying property handlers
1 parent f9975dc commit c7011a9

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/Container.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class Container {
115115
service.instance = new (type.bind.apply(type, params))();
116116
}
117117

118-
this.applyPropertyHandlers(type);
118+
this.applyPropertyHandlers(type, service.instance);
119119
return service.instance as T;
120120
}
121121

@@ -230,18 +230,13 @@ export class Container {
230230
/**
231231
* Applies all registered handlers on a given target class.
232232
*/
233-
private static applyPropertyHandlers(target: Function) {
233+
private static applyPropertyHandlers(target: Function, instance: { [key: string]: any }) {
234234
this.handlers.forEach(handler => {
235-
if (handler.index) return;
235+
if (typeof handler.index === "number") return;
236236
if (handler.object.constructor !== target && !(target.prototype instanceof handler.object.constructor))
237237
return;
238238

239-
Object.defineProperty(handler.object, handler.propertyName, {
240-
enumerable: true,
241-
writable: true,
242-
configurable: true,
243-
value: handler.value()
244-
});
239+
instance[handler.propertyName] = handler.value();
245240
});
246241
}
247242

0 commit comments

Comments
 (0)