diff --git a/src/SocketLabs/InjectionApi/SocketLabsClient.cs b/src/SocketLabs/InjectionApi/SocketLabsClient.cs
index 700bbf2..58196fb 100644
--- a/src/SocketLabs/InjectionApi/SocketLabsClient.cs
+++ b/src/SocketLabs/InjectionApi/SocketLabsClient.cs
@@ -47,8 +47,10 @@ public class SocketLabsClient : ISocketLabsClient , IDisposable
///
/// Your SocketLabs ServerId number.
/// Your SocketLabs Injection API key.
- public SocketLabsClient(int serverId, string apiKey):this(serverId, apiKey, null)
+ public SocketLabsClient(int serverId, string apiKey)
{
+ _serverId = serverId;
+ _apiKey = apiKey;
_httpClient = BuildHttpClient(null);
}
@@ -65,13 +67,33 @@ public SocketLabsClient(int serverId, string apiKey, IWebProxy optionalProxy)
_httpClient = BuildHttpClient(optionalProxy);
}
+ ///
+ /// Creates a new instance of the SocketLabsClient with a provided HttpClient.
+ ///
+ /// Your SocketLabs ServerId number.
+ /// Your SocketLabs Injection API key.
+ /// The HttpClient instance you would like to use.
+ public SocketLabsClient(int serverId, string apiKey, HttpClient httpClient)
+ {
+ _serverId = serverId;
+ _apiKey = apiKey;
+
+ _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
+ ConfigureHttpClient(httpClient);
+ }
+
private HttpClient BuildHttpClient(IWebProxy optionalProxy)
{
var httpClient = optionalProxy != null ? new HttpClient(new HttpClientHandler() {UseProxy = true, Proxy = optionalProxy}) : new HttpClient();
- httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
+ ConfigureHttpClient(httpClient);
return httpClient;
}
+ private void ConfigureHttpClient(HttpClient httpClient)
+ {
+ httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
+ }
+
///
/// Quickly and easily send a basic message without the need to build up a message object
/// or instantiate a SocketLabsClient.