From 16c124b75bad51d0b8b5627ada18176bff72f9a9 Mon Sep 17 00:00:00 2001 From: fanliang11 <137629448@qq.com> Date: Mon, 7 Jun 2021 00:18:42 +0800 Subject: [PATCH] Fix memory leak problem based on routepath call Fix memory leak problem based on routepath call #413 --- .../Implementation/ServiceProxyProvider.cs | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyProvider.cs b/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyProvider.cs index daa7d6c95..c8e2e98ad 100644 --- a/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyProvider.cs +++ b/src/Surging.Core/Surging.Core.ProxyGenerator/Implementation/ServiceProxyProvider.cs @@ -17,30 +17,33 @@ public ServiceProxyProvider( IServiceRouteProvider serviceRouteProvider _serviceProvider = serviceProvider; } - public async Task Invoke(IDictionary parameters, string routePath) + public async Task Invoke(IDictionary parameters, string routePath) { var serviceRoute= await _serviceRouteProvider.GetRouteByPath(routePath.ToLower()); T result = default(T); if (parameters.ContainsKey("serviceKey")) { var serviceKey = parameters["serviceKey"].ToString(); - var proxy = ServiceResolver.Current.GetService(serviceKey); - if (proxy == null) - { - proxy = new RemoteServiceProxy(serviceKey.ToString(), _serviceProvider); - ServiceResolver.Current.Register(serviceKey.ToString(), proxy); - } + //var proxy = ServiceResolver.Current.GetService(serviceKey); + //if (proxy == null) + //{ + // proxy = new RemoteServiceProxy(serviceKey.ToString(), _serviceProvider); + // ServiceResolver.Current.Register(serviceKey.ToString(), proxy); + //} + var proxy = new RemoteServiceProxy(serviceKey, _serviceProvider); result = await proxy.Invoke(parameters, serviceRoute.ServiceDescriptor.Id); } else { - var proxy = ServiceResolver.Current.GetService(); - if (proxy == null) - { - proxy = new RemoteServiceProxy(null, _serviceProvider); - ServiceResolver.Current.Register(null, proxy); - } + //var proxy = ServiceResolver.Current.GetService(); + + //if (proxy == null) + //{ + // proxy = new RemoteServiceProxy(null, _serviceProvider); + // ServiceResolver.Current.Register(null, proxy); + //} + var proxy = new RemoteServiceProxy(null, _serviceProvider); result = await proxy.Invoke(parameters, serviceRoute.ServiceDescriptor.Id); } return result; @@ -52,22 +55,26 @@ public async Task Invoke(IDictionary parameters, string ro T result = default(T); if (!string.IsNullOrEmpty(serviceKey)) { - var proxy = ServiceResolver.Current.GetService(serviceKey); - if (proxy == null) - { - proxy = new RemoteServiceProxy(serviceKey, _serviceProvider); - ServiceResolver.Current.Register(serviceKey, proxy); - } + // var proxy = ServiceResolver.Current.GetService(serviceKey); + + //if (proxy == null) + //{ + // proxy = new RemoteServiceProxy(serviceKey, _serviceProvider); + // ServiceResolver.Current.Register(serviceKey, proxy); + //} + var proxy = new RemoteServiceProxy(serviceKey, _serviceProvider); result = await proxy.Invoke(parameters, serviceRoute.ServiceDescriptor.Id); } else { - var proxy = ServiceResolver.Current.GetService(); - if (proxy == null) - { - proxy = new RemoteServiceProxy(null, _serviceProvider); - ServiceResolver.Current.Register(null, proxy); - } + //var proxy = ServiceResolver.Current.GetService(); + + //if (proxy == null) + //{ + // proxy = new RemoteServiceProxy(null, _serviceProvider); + // ServiceResolver.Current.Register(null, proxy); + //} + var proxy = new RemoteServiceProxy(null, _serviceProvider); result = await proxy.Invoke(parameters, serviceRoute.ServiceDescriptor.Id); } return result;