@@ -64,71 +64,42 @@ public abstract class ConnectionConfiguration<T> : IConnectionConfigurationValue
6464 where T : ConnectionConfiguration < T >
6565 {
6666 private readonly IConnection _connection ;
67-
6867 private readonly IConnectionPool _connectionPool ;
69-
7068 private readonly NameValueCollection _headers = new NameValueCollection ( ) ;
71-
7269 private readonly NameValueCollection _queryString = new NameValueCollection ( ) ;
7370 private readonly SemaphoreSlim _semaphore = new SemaphoreSlim ( 1 , 1 ) ;
74-
71+ private readonly ElasticsearchUrlFormatter _urlFormatter ;
72+
7573 private BasicAuthenticationCredentials _basicAuthCredentials ;
76-
7774 private X509CertificateCollection _clientCertificates ;
7875 private Action < IApiCallDetails > _completedRequestHandler = DefaultCompletedRequestHandler ;
79-
8076 private int _connectionLimit ;
81-
8277 private TimeSpan ? _deadTimeout ;
83-
8478 private bool _disableAutomaticProxyDetection = false ;
85-
8679 private bool _disableDirectStreaming = false ;
87-
8880 private bool _disablePings ;
89-
9081 private bool _enableHttpCompression ;
91-
9282 private bool _enableHttpPipelining = true ;
93-
9483 private TimeSpan ? _keepAliveInterval ;
95-
9684 private TimeSpan ? _keepAliveTime ;
97-
9885 private TimeSpan ? _maxDeadTimeout ;
99-
10086 private int ? _maxRetries ;
101-
10287 private TimeSpan ? _maxRetryTimeout ;
103-
10488 private Func < Node , bool > _nodePredicate = DefaultNodePredicate ;
10589 private Action < RequestData > _onRequestDataCreated = DefaultRequestDataCreated ;
106-
10790 private TimeSpan ? _pingTimeout ;
108-
10991 private bool _prettyJson ;
110-
11192 private string _proxyAddress ;
112-
11393 private string _proxyPassword ;
114-
11594 private string _proxyUsername ;
116-
11795 private TimeSpan _requestTimeout ;
118-
11996 private Func < object , X509Certificate , X509Chain , SslPolicyErrors , bool > _serverCertificateValidationCallback ;
120-
12197 private IReadOnlyCollection < int > _skipDeserializationForStatusCodes = new ReadOnlyCollection < int > ( new int [ ] { } ) ;
122-
12398 private TimeSpan ? _sniffLifeSpan ;
124-
12599 private bool _sniffOnConnectionFault ;
126-
127100 private bool _sniffOnStartup ;
128-
129101 private bool _throwExceptions ;
130-
131- private readonly ElasticsearchUrlFormatter _urlFormatter ;
102+ private string _uniqueId = Guid . NewGuid ( ) . ToString ( "N" ) ;
132103
133104 protected ConnectionConfiguration ( IConnectionPool connectionPool , IConnection connection , IElasticsearchSerializer requestResponseSerializer )
134105 {
@@ -147,6 +118,7 @@ protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection co
147118 _urlFormatter = new ElasticsearchUrlFormatter ( this ) ;
148119 }
149120
121+ string IConnectionConfigurationValues . Id => _uniqueId ;
150122 protected IElasticsearchSerializer UseThisRequestResponseSerializer { get ; set ; }
151123 BasicAuthenticationCredentials IConnectionConfigurationValues . BasicAuthenticationCredentials => _basicAuthCredentials ;
152124 SemaphoreSlim IConnectionConfigurationValues . BootstrapLock => _semaphore ;
@@ -205,11 +177,11 @@ private static void DefaultRequestDataCreated(RequestData response) { }
205177
206178 private static bool DefaultNodePredicate ( Node node ) => true ;
207179
208- private T Assign < TValue > ( TValue value , Action < ConnectionConfiguration < T > , TValue > assigner ) => Fluent . Assign ( ( T ) this , value , assigner ) ;
180+ protected T UpdateId ( ) => Fluent . Assign < T , T , string > ( ( T ) this , Guid . NewGuid ( ) . ToString ( "N" ) , ( a , v ) => a . _uniqueId = v ) ;
181+
182+ protected T Assign < TValue > ( TValue value , Action < T , TValue > assigner ) => Fluent . Assign ( ( T ) this , value , assigner ) . UpdateId ( ) ;
209183
210- /// <summary>
211- /// The default serializer used to serialize documents to and from JSON
212- /// </summary>
184+ /// <summary> The default serializer used to serialize documents to and from JSON </summary>
213185 protected virtual IElasticsearchSerializer DefaultSerializer ( T settings ) => new LowLevelRequestResponseSerializer ( ) ;
214186
215187 /// <summary>
@@ -225,9 +197,7 @@ public T EnableTcpKeepAlive(TimeSpan keepAliveTime, TimeSpan keepAliveInterval)
225197 Assign ( keepAliveTime , ( a , v ) => a . _keepAliveTime = v )
226198 . Assign ( keepAliveInterval , ( a , v ) => a . _keepAliveInterval = v ) ;
227199
228- /// <summary>
229- /// The maximum number of retries for a given request,
230- /// </summary>
200+ /// <summary> The maximum number of retries for a given request </summary>
231201 public T MaximumRetries ( int maxRetries ) => Assign ( maxRetries , ( a , v ) => a . _maxRetries = v ) ;
232202
233203 /// <summary>
@@ -341,14 +311,10 @@ public T SniffOnConnectionFault(bool sniffsOnConnectionFault = true) =>
341311 /// <summary>
342312 /// If your connection has to go through proxy, use this method to specify the proxy url
343313 /// </summary>
344- public T Proxy ( Uri proxyAdress , string username , string password )
345- {
346- proxyAdress . ThrowIfNull ( nameof ( proxyAdress ) ) ;
347- _proxyAddress = proxyAdress . ToString ( ) ;
348- _proxyUsername = username ;
349- _proxyPassword = password ;
350- return ( T ) this ;
351- }
314+ public T Proxy ( Uri proxyAdress , string username , string password ) =>
315+ Assign ( proxyAdress . ToString ( ) , ( a , v ) => a . _proxyAddress = v )
316+ . Assign ( username , ( a , v ) => a . _proxyUsername = v )
317+ . Assign ( password , ( a , v ) => a . _proxyPassword = v ) ;
352318
353319 /// <summary>
354320 /// Forces all requests to have ?pretty=true querystring parameter appended,
@@ -422,13 +388,7 @@ public T BasicAuthentication(string userName, string password) =>
422388 /// verbatim.
423389 /// </summary>
424390 /// <param name="predicate">Return true if you want the node to be used for API calls</param>
425- public T NodePredicate ( Func < Node , bool > predicate )
426- {
427- if ( predicate == null ) return ( T ) this ;
428-
429- _nodePredicate = predicate ;
430- return ( T ) this ;
431- }
391+ public T NodePredicate ( Func < Node , bool > predicate ) => Assign ( predicate ?? DefaultNodePredicate , ( a , v ) => a . _nodePredicate = predicate ) ;
432392
433393 /// <summary>
434394 /// Turns on settings that aid in debugging like DisableDirectStreaming() and PrettyJson()
@@ -440,22 +400,20 @@ public T NodePredicate(Func<Node, bool> predicate)
440400 /// ConnectionSettings. If no callback is passed, DebugInformation from the response
441401 /// will be written to the debug output by default.
442402 /// </param>
443- public T EnableDebugMode ( Action < IApiCallDetails > onRequestCompleted = null )
444- {
445- _disableDirectStreaming = true ;
446- PrettyJson ( true ) ;
447- IncludeServerStackTraceOnError ( true ) ;
448-
449- var originalCompletedRequestHandler = _completedRequestHandler ;
450- var debugCompletedRequestHandler = onRequestCompleted ?? ( d => Debug . WriteLine ( d . DebugInformation ) ) ;
451- _completedRequestHandler = d =>
452- {
453- originalCompletedRequestHandler ? . Invoke ( d ) ;
454- debugCompletedRequestHandler ? . Invoke ( d ) ;
455- } ;
456-
457- return ( T ) this ;
458- }
403+ public T EnableDebugMode ( Action < IApiCallDetails > onRequestCompleted = null ) =>
404+ PrettyJson ( )
405+ . IncludeServerStackTraceOnError ( )
406+ . DisableDirectStreaming ( )
407+ . Assign ( onRequestCompleted , ( a , v ) =>
408+ {
409+ var originalCompletedRequestHandler = _completedRequestHandler ;
410+ var debugCompletedRequestHandler = v ?? ( d => Debug . WriteLine ( d . DebugInformation ) ) ;
411+ _completedRequestHandler = d =>
412+ {
413+ originalCompletedRequestHandler ? . Invoke ( d ) ;
414+ debugCompletedRequestHandler . Invoke ( d ) ;
415+ } ;
416+ } ) ;
459417
460418 /// <summary>
461419 /// Register a ServerCertificateValidationCallback, this is called per endpoint until it returns true.
0 commit comments