diff --git a/plugins/simple-di/src/decorators/helpers/patch-methods.ts b/plugins/simple-di/src/decorators/helpers/patch-methods.ts index 1f449880..49225889 100644 --- a/plugins/simple-di/src/decorators/helpers/patch-methods.ts +++ b/plugins/simple-di/src/decorators/helpers/patch-methods.ts @@ -45,10 +45,12 @@ function patchMethod(constructor: Registrable, methodName: string | symbol }; } -const _PROXY_CACHE = new WeakMap(); +const _PROXY_CACHE = new WeakMap>(); function createProxy(target: Constructable, request: unknown, reply: unknown): unknown { - if (_PROXY_CACHE.has(request as WeakKey)) return _PROXY_CACHE.get(request as WeakKey); + if (!_PROXY_CACHE.has(target)) _PROXY_CACHE.set(target, new WeakMap()); + const targetProxyCache = _PROXY_CACHE.get(target) as WeakMap; + if (targetProxyCache.has(request as WeakKey)) return targetProxyCache.get(request as WeakKey); const proxy = new Proxy(target, { get(target, p) { @@ -70,5 +72,5 @@ function createProxy(target: Constructable, request: unknown, reply: unkno }, }); - return _PROXY_CACHE.set(request as WeakKey, proxy).get(request as WeakKey); + return targetProxyCache.set(request as WeakKey, proxy).get(request as WeakKey); }