@@ -21,6 +21,8 @@ public class GraphQLHttpClient : IGraphQLClient
2121 private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource ( ) ;
2222 private readonly ConcurrentDictionary < Tuple < GraphQLRequest , Type > , object > _subscriptionStreams = new ConcurrentDictionary < Tuple < GraphQLRequest , Type > , object > ( ) ;
2323
24+ private readonly bool _disposeHttpClient = false ;
25+
2426 /// <summary>
2527 /// the json serializer
2628 /// </summary>
@@ -54,7 +56,12 @@ public GraphQLHttpClient(Uri endPoint, IGraphQLWebsocketJsonSerializer serialize
5456
5557 public GraphQLHttpClient ( Action < GraphQLHttpClientOptions > configure , IGraphQLWebsocketJsonSerializer serializer ) : this ( configure . New ( ) , serializer ) { }
5658
57- public GraphQLHttpClient ( GraphQLHttpClientOptions options , IGraphQLWebsocketJsonSerializer serializer ) : this ( options , serializer , new HttpClient ( options . HttpMessageHandler ) ) { }
59+ public GraphQLHttpClient ( GraphQLHttpClientOptions options , IGraphQLWebsocketJsonSerializer serializer ) : this (
60+ options , serializer , new HttpClient ( options . HttpMessageHandler ) )
61+ {
62+ // set this flag to dispose the internally created HttpClient when GraphQLHttpClient gets disposed
63+ _disposeHttpClient = true ;
64+ }
5865
5966 public GraphQLHttpClient ( GraphQLHttpClientOptions options , IGraphQLWebsocketJsonSerializer serializer , HttpClient httpClient )
6067 {
@@ -195,7 +202,8 @@ protected virtual void Dispose(bool disposing)
195202 {
196203 Debug . WriteLine ( $ "Disposing GraphQLHttpClient on endpoint { Options . EndPoint } ") ;
197204 _cancellationTokenSource . Cancel ( ) ;
198- HttpClient . Dispose ( ) ;
205+ if ( _disposeHttpClient )
206+ HttpClient . Dispose ( ) ;
199207 if ( _lazyHttpWebSocket . IsValueCreated )
200208 _lazyHttpWebSocket . Value . Dispose ( ) ;
201209 _cancellationTokenSource . Dispose ( ) ;
0 commit comments