Skip to content

Commit

Permalink
Merge pull request #231 from liquizard/230-custom-httpclient
Browse files Browse the repository at this point in the history
Allow IRpcClient creation with custom HttpClient. Fixes issue #230, update to 0.4.12
  • Loading branch information
liquizard committed Oct 14, 2021
2 parents 2c987eb + 8ac5006 commit 4ed08ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SharedBuildProperties.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Product>Solnet</Product>
<Version>0.4.11</Version>
<Version>0.4.12</Version>
<Copyright>Copyright 2021 &#169; Solnet</Copyright>
<Authors>blockmountain</Authors>
<PublisherName>blockmountain</PublisherName>
Expand Down
32 changes: 28 additions & 4 deletions src/Solnet.Rpc/ClientFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using System.Net.Http;

namespace Solnet.Rpc
{
Expand Down Expand Up @@ -45,7 +46,19 @@ public static class ClientFactory
/// <param name="cluster">The network cluster.</param>
/// <param name="logger">The logger.</param>
/// <returns>The http client.</returns>
public static IRpcClient GetClient(Cluster cluster, ILogger logger = null)
public static IRpcClient GetClient(Cluster cluster, ILogger logger)
{
return GetClient(cluster, logger, null);
}

/// <summary>
/// Instantiate a http client.
/// </summary>
/// <param name="cluster">The network cluster.</param>
/// <param name="logger">The logger.</param>
/// <param name="httpClient">A HttpClient instance. If null, a new instance will be created.</param>
/// <returns>The http client.</returns>
public static IRpcClient GetClient(Cluster cluster, ILogger logger = null, HttpClient httpClient = null)
{
var url = cluster switch
{
Expand All @@ -68,7 +81,7 @@ public static IRpcClient GetClient(Cluster cluster, ILogger logger = null)
}).CreateLogger<IRpcClient>();
#endif

return GetClient(url, logger);
return GetClient(url, logger, httpClient);
}

/// <summary>
Expand All @@ -77,10 +90,21 @@ public static IRpcClient GetClient(Cluster cluster, ILogger logger = null)
/// <param name="url">The network cluster url.</param>
/// <param name="logger">The logger.</param>
/// <returns>The http client.</returns>
public static IRpcClient GetClient(string url, ILogger logger = null)
public static IRpcClient GetClient(string url, ILogger logger)
{
return GetClient(url, logger, null);
}

return new SolanaRpcClient(url, logger);
/// <summary>
/// Instantiate a http client.
/// </summary>
/// <param name="url">The network cluster url.</param>
/// <param name="logger">The logger.</param>
/// <param name="httpClient">A HttpClient instance. If null, a new instance will be created.</param>
/// <returns>The http client.</returns>
public static IRpcClient GetClient(string url, ILogger logger = null, HttpClient httpClient = null)
{
return new SolanaRpcClient(url, logger, httpClient);
}

/// <summary>
Expand Down

0 comments on commit 4ed08ca

Please sign in to comment.