@@ -113,25 +113,31 @@ public ForceClient(string instanceUrl, string apiVersion, string accessToken, Ht
113113 /// <param name="httpClient">Optional HttpClient object. Defaults to a shared static instance for best performance, but a custom HttpClient can be specified when custom properties are needed e.g. proxy settings.</param>
114114 public static async Task < ForceClient > FromClientCredentialsAsync ( string clientId , string clientSecret , string tokenRequestEndpoint , string apiVersion = null , HttpClient httpClient = null )
115115 {
116- AuthenticationClient authClient = new AuthenticationClient ( apiVersion , httpClient ) ;
117- await authClient . ClientCredentialsAsync ( clientId , clientSecret , tokenRequestEndpoint ) . ConfigureAwait ( false ) ;
118- return new ForceClient ( authClient . AccessInfo . InstanceUrl , authClient . ApiVersion , authClient . AccessInfo . AccessToken , httpClient , authClient . AccessInfo ) ;
116+ using ( AuthenticationClient authClient = new AuthenticationClient ( apiVersion , httpClient ) )
117+ {
118+ await authClient . ClientCredentialsAsync ( clientId , clientSecret , tokenRequestEndpoint ) . ConfigureAwait ( false ) ;
119+ return new ForceClient ( authClient . AccessInfo . InstanceUrl , authClient . ApiVersion , authClient . AccessInfo . AccessToken , httpClient , authClient . AccessInfo ) ;
120+ }
119121 }
120122
121123 private async Task Login ( string clientId , string clientSecret , string username , string password , string tokenRequestEndpoint , string apiVersion = null , HttpClient httpClient = null )
122124 {
123- AuthenticationClient authClient = new AuthenticationClient ( apiVersion , httpClient ) ;
124- await authClient . UsernamePasswordAsync ( clientId , clientSecret , username , password , tokenRequestEndpoint ) . ConfigureAwait ( false ) ;
125+ using ( AuthenticationClient authClient = new AuthenticationClient ( apiVersion , httpClient ) )
126+ {
127+ await authClient . UsernamePasswordAsync ( clientId , clientSecret , username , password , tokenRequestEndpoint ) . ConfigureAwait ( false ) ;
125128
126- Initialize ( authClient . AccessInfo . InstanceUrl , authClient . ApiVersion , authClient . AccessInfo . AccessToken , httpClient , authClient . AccessInfo ) ;
129+ Initialize ( authClient . AccessInfo . InstanceUrl , authClient . ApiVersion , authClient . AccessInfo . AccessToken , httpClient , authClient . AccessInfo ) ;
130+ }
127131 }
128132
129133 private async Task LoginClientCredentials ( string clientId , string clientSecret , string tokenRequestEndpoint , string apiVersion = null , HttpClient httpClient = null )
130134 {
131- AuthenticationClient authClient = new AuthenticationClient ( apiVersion , httpClient ) ;
132- await authClient . ClientCredentialsAsync ( clientId , clientSecret , tokenRequestEndpoint ) . ConfigureAwait ( false ) ;
135+ using ( AuthenticationClient authClient = new AuthenticationClient ( apiVersion , httpClient ) )
136+ {
137+ await authClient . ClientCredentialsAsync ( clientId , clientSecret , tokenRequestEndpoint ) . ConfigureAwait ( false ) ;
133138
134- Initialize ( authClient . AccessInfo . InstanceUrl , authClient . ApiVersion , authClient . AccessInfo . AccessToken , httpClient , authClient . AccessInfo ) ;
139+ Initialize ( authClient . AccessInfo . InstanceUrl , authClient . ApiVersion , authClient . AccessInfo . AccessToken , httpClient , authClient . AccessInfo ) ;
140+ }
135141 }
136142
137143 private void Initialize ( string instanceUrl , string apiVersion , string accessToken , HttpClient httpClient = null , AccessTokenResponse accessInfo = null )
@@ -988,15 +994,11 @@ public async Task<DescribeGlobal> DescribeGlobal()
988994 #endregion
989995
990996 /// <summary>
991- /// Dispose client - only disposes instance HttpClient, if any. Shared static HttpClient is left as-is.
997+ /// Dispose client - does not dispose the HttpClient.
998+ /// <para>A caller-supplied HttpClient is owned by the caller, and the shared static HttpClient is left as-is.</para>
992999 /// </summary>
9931000 public void Dispose ( )
9941001 {
995- //only dispose instance member, if any
996- if ( _httpClient != null )
997- {
998- _httpClient . Dispose ( ) ;
999- }
10001002 }
10011003 }
10021004}
0 commit comments