Skip to content

Commit 199e7c5

Browse files
committed
Moved location of fix to make it available for all user flows
1 parent 56eee32 commit 199e7c5

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

Client/ApiClient.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,21 @@ public class RestClientFactory
3838
{
3939
private static readonly ConcurrentDictionary<int, Lazy<RestClient>> _restClientInstances = new ConcurrentDictionary<int, Lazy<RestClient>>();
4040

41-
public static RestClient GetRestClient(RestClientOptions clientOptions)
41+
public static RestClient GetRestClient(Configuration configuration, RestClientOptions clientOptions)
4242
{
43+
if (configuration.MerchantConfigDictionaryObj != null)
44+
{
45+
var merchantConfig = new MerchantConfig(configuration.MerchantConfigDictionaryObj);
46+
47+
ServicePointManager.DefaultConnectionLimit = int.Parse(merchantConfig.MaxConnectionPoolSize);
48+
ServicePointManager.MaxServicePointIdleTime = int.Parse(merchantConfig.KeepAliveTime);
49+
}
50+
else
51+
{
52+
ServicePointManager.DefaultConnectionLimit = int.Parse(Constants.DefaultMaxConnectionPoolSize);
53+
ServicePointManager.MaxServicePointIdleTime = int.Parse(Constants.DefaultKeepAliveTime);
54+
}
55+
4356
int hash = GetHashOfRestClientOptions(clientOptions);
4457

4558
if (!_restClientInstances.TryGetValue(hash, out Lazy<RestClient> lazyClient))
@@ -120,19 +133,6 @@ public ApiClient(Configuration config = null)
120133
{
121134
logger = LogManager.GetCurrentClassLogger();
122135
}
123-
124-
if (Configuration.MerchantConfigDictionaryObj != null)
125-
{
126-
var merchantConfig = new MerchantConfig(Configuration.MerchantConfigDictionaryObj);
127-
128-
ServicePointManager.DefaultConnectionLimit = int.Parse(merchantConfig.MaxConnectionPoolSize);
129-
ServicePointManager.MaxServicePointIdleTime = int.Parse(merchantConfig.KeepAliveTime);
130-
}
131-
else
132-
{
133-
ServicePointManager.DefaultConnectionLimit = int.Parse(Constants.DefaultMaxConnectionPoolSize);
134-
ServicePointManager.MaxServicePointIdleTime = int.Parse(Constants.DefaultKeepAliveTime);
135-
}
136136
}
137137

138138
/// <summary>
@@ -348,7 +348,7 @@ public object CallApi(
348348

349349
// RestClient.ClearHandlers();
350350

351-
var actualRestClient = RestClientFactory.GetRestClient(newRestClientOptions);
351+
var actualRestClient = RestClientFactory.GetRestClient(Configuration, newRestClientOptions);
352352

353353
// Logging Request Headers
354354
var headerPrintOutput = new StringBuilder();
@@ -508,7 +508,7 @@ public async System.Threading.Tasks.Task<object> CallApiAsync(
508508

509509
var newRestClientOptions = GetRestClientOptions(Configuration);
510510

511-
var actualRestClient = RestClientFactory.GetRestClient(newRestClientOptions);
511+
var actualRestClient = RestClientFactory.GetRestClient(Configuration, newRestClientOptions);
512512

513513
InterceptRequest(request);
514514
var response = await actualRestClient.ExecuteAsync(request);

generator/cybersource-csharp-template/ApiClient.mustache

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,21 @@ namespace {{packageName}}.Client
3939
{
4040
private static readonly ConcurrentDictionary<int, Lazy<RestClient>> _restClientInstances = new ConcurrentDictionary<int, Lazy<RestClient>>();
4141
42-
public static RestClient GetRestClient(RestClientOptions clientOptions)
42+
public static RestClient GetRestClient(Configuration configuration, RestClientOptions clientOptions)
4343
{
44+
if (configuration.MerchantConfigDictionaryObj != null)
45+
{
46+
var merchantConfig = new MerchantConfig(configuration.MerchantConfigDictionaryObj);
47+
48+
ServicePointManager.DefaultConnectionLimit = int.Parse(merchantConfig.MaxConnectionPoolSize);
49+
ServicePointManager.MaxServicePointIdleTime = int.Parse(merchantConfig.KeepAliveTime);
50+
}
51+
else
52+
{
53+
ServicePointManager.DefaultConnectionLimit = int.Parse(Constants.DefaultMaxConnectionPoolSize);
54+
ServicePointManager.MaxServicePointIdleTime = int.Parse(Constants.DefaultKeepAliveTime);
55+
}
56+
4457
int hash = GetHashOfRestClientOptions(clientOptions);
4558

4659
if (!_restClientInstances.TryGetValue(hash, out Lazy<RestClient> lazyClient))
@@ -124,19 +137,6 @@ namespace {{packageName}}.Client
124137
{
125138
logger = LogManager.GetCurrentClassLogger();
126139
}
127-
128-
if (Configuration.MerchantConfigDictionaryObj != null)
129-
{
130-
var merchantConfig = new MerchantConfig(Configuration.MerchantConfigDictionaryObj);
131-
132-
ServicePointManager.DefaultConnectionLimit = int.Parse(merchantConfig.MaxConnectionPoolSize);
133-
ServicePointManager.MaxServicePointIdleTime = int.Parse(merchantConfig.KeepAliveTime);
134-
}
135-
else
136-
{
137-
ServicePointManager.DefaultConnectionLimit = int.Parse(Constants.DefaultMaxConnectionPoolSize);
138-
ServicePointManager.MaxServicePointIdleTime = int.Parse(Constants.DefaultKeepAliveTime);
139-
}
140140
}
141141

142142
/// <summary>
@@ -387,7 +387,7 @@ namespace {{packageName}}.Client
387387

388388
// RestClient.ClearHandlers();
389389

390-
var actualRestClient = RestClientFactory.GetRestClient(newRestClientOptions);
390+
var actualRestClient = RestClientFactory.GetRestClient(Configuration, newRestClientOptions);
391391

392392
// Logging Request Headers
393393
var headerPrintOutput = new StringBuilder();
@@ -559,7 +559,7 @@ namespace {{packageName}}.Client
559559

560560
var newRestClientOptions = GetRestClientOptions(Configuration);
561561

562-
var actualRestClient = RestClientFactory.GetRestClient(newRestClientOptions);
562+
var actualRestClient = RestClientFactory.GetRestClient(Configuration, newRestClientOptions);
563563

564564
InterceptRequest(request);
565565
var response = await actualRestClient.Execute{{^netStandard}}Async{{/netStandard}}(request);

0 commit comments

Comments
 (0)