Skip to content

Commit

Permalink
Fix memory leak problem based on routepath call
Browse files Browse the repository at this point in the history
Fix memory leak problem based on routepath call #413
  • Loading branch information
fanliang11 authored Jun 6, 2021
1 parent cbfc485 commit 16c124b
Showing 1 changed file with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@ public ServiceProxyProvider( IServiceRouteProvider serviceRouteProvider
_serviceProvider = serviceProvider;
}

public async Task<T> Invoke<T>(IDictionary<string, object> parameters, string routePath)
public async Task<T> Invoke<T>(IDictionary<string, object> 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<RemoteServiceProxy>(serviceKey);
if (proxy == null)
{
proxy = new RemoteServiceProxy(serviceKey.ToString(), _serviceProvider);
ServiceResolver.Current.Register(serviceKey.ToString(), proxy);
}
//var proxy = ServiceResolver.Current.GetService<RemoteServiceProxy>(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<T>(parameters, serviceRoute.ServiceDescriptor.Id);

}
else
{
var proxy = ServiceResolver.Current.GetService<RemoteServiceProxy>();
if (proxy == null)
{
proxy = new RemoteServiceProxy(null, _serviceProvider);
ServiceResolver.Current.Register(null, proxy);
}
//var proxy = ServiceResolver.Current.GetService<RemoteServiceProxy>();

//if (proxy == null)
//{
// proxy = new RemoteServiceProxy(null, _serviceProvider);
// ServiceResolver.Current.Register(null, proxy);
//}
var proxy = new RemoteServiceProxy(null, _serviceProvider);
result = await proxy.Invoke<T>(parameters, serviceRoute.ServiceDescriptor.Id);
}
return result;
Expand All @@ -52,22 +55,26 @@ public async Task<T> Invoke<T>(IDictionary<string, object> parameters, string ro
T result = default(T);
if (!string.IsNullOrEmpty(serviceKey))
{
var proxy = ServiceResolver.Current.GetService<RemoteServiceProxy>(serviceKey);
if (proxy == null)
{
proxy = new RemoteServiceProxy(serviceKey, _serviceProvider);
ServiceResolver.Current.Register(serviceKey, proxy);
}
// var proxy = ServiceResolver.Current.GetService<RemoteServiceProxy>(serviceKey);

//if (proxy == null)
//{
// proxy = new RemoteServiceProxy(serviceKey, _serviceProvider);
// ServiceResolver.Current.Register(serviceKey, proxy);
//}
var proxy = new RemoteServiceProxy(serviceKey, _serviceProvider);
result = await proxy.Invoke<T>(parameters, serviceRoute.ServiceDescriptor.Id);
}
else
{
var proxy = ServiceResolver.Current.GetService<RemoteServiceProxy>();
if (proxy == null)
{
proxy = new RemoteServiceProxy(null, _serviceProvider);
ServiceResolver.Current.Register(null, proxy);
}
//var proxy = ServiceResolver.Current.GetService<RemoteServiceProxy>();

//if (proxy == null)
//{
// proxy = new RemoteServiceProxy(null, _serviceProvider);
// ServiceResolver.Current.Register(null, proxy);
//}
var proxy = new RemoteServiceProxy(null, _serviceProvider);
result = await proxy.Invoke<T>(parameters, serviceRoute.ServiceDescriptor.Id);
}
return result;
Expand Down

0 comments on commit 16c124b

Please sign in to comment.