Browse Source

renamed names to follow convention HttpClientFactory + RestClient or RestClientProvider.

pull/1806/head
emorell96 4 years ago
parent
commit
1c31bc8abe
3 changed files with 11 additions and 11 deletions
  1. +6
    -6
      src/Discord.Net.Rest/Extensions/ServiceCollectionExtensions.cs
  2. +3
    -3
      src/Discord.Net.Rest/Net/HttpClientFactoryClientProvider.cs
  3. +2
    -2
      src/Discord.Net.Rest/Net/HttpClientFactoryRestClient.cs

+ 6
- 6
src/Discord.Net.Rest/Extensions/ServiceCollectionExtensions.cs View File

@@ -18,7 +18,7 @@ namespace Discord.Rest.Extensions
{ {
public static IServiceCollection AddScopedDiscordRestClient(this IServiceCollection services, bool useProxy = false) public static IServiceCollection AddScopedDiscordRestClient(this IServiceCollection services, bool useProxy = false)
{ {
services.AddHttpClient("HttpFactoryRestClientProvider")
services.AddHttpClient("HttpClientFactoryRestClientProvider")
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{ {
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
@@ -28,12 +28,12 @@ namespace Discord.Rest.Extensions






services.AddTransient<HttpFactoryRestClientProvider>(provider => new HttpFactoryRestClientProvider(provider.GetRequiredService<IHttpClientFactory>()));
services.AddTransient<HttpClientFactoryRestClientProvider>(provider => new HttpClientFactoryRestClientProvider(provider.GetRequiredService<IHttpClientFactory>()));
services.AddScoped<DiscordRestClient>(provider => services.AddScoped<DiscordRestClient>(provider =>
{ {
var config = new DiscordRestConfig var config = new DiscordRestConfig
{ {
RestClientProvider = provider.GetRequiredService<HttpFactoryRestClientProvider>().Instance
RestClientProvider = provider.GetRequiredService<HttpClientFactoryRestClientProvider>().Instance
}; };
return new DiscordRestClient(config); return new DiscordRestClient(config);
}); });
@@ -43,7 +43,7 @@ namespace Discord.Rest.Extensions


public static IServiceCollection AddTransientDiscordRestClient(this IServiceCollection services, bool useProxy = false) //where should we put this useProxy options, I haven't fully understood where the original code takes this from. public static IServiceCollection AddTransientDiscordRestClient(this IServiceCollection services, bool useProxy = false) //where should we put this useProxy options, I haven't fully understood where the original code takes this from.
{ {
services.AddHttpClient("HttpFactoryRestClientProvider")
services.AddHttpClient("HttpClientFactoryRestClientProvider")
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{ {
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
@@ -53,12 +53,12 @@ namespace Discord.Rest.Extensions






services.AddTransient<HttpFactoryRestClientProvider>(provider => new HttpFactoryRestClientProvider(provider.GetRequiredService<IHttpClientFactory>()));
services.AddTransient<HttpClientFactoryRestClientProvider>(provider => new HttpClientFactoryRestClientProvider(provider.GetRequiredService<IHttpClientFactory>()));
services.AddTransient<DiscordRestClient>(provider => services.AddTransient<DiscordRestClient>(provider =>
{ {
var config = new DiscordRestConfig var config = new DiscordRestConfig
{ {
RestClientProvider = provider.GetRequiredService<HttpFactoryRestClientProvider>().Instance
RestClientProvider = provider.GetRequiredService<HttpClientFactoryRestClientProvider>().Instance
}; };
return new DiscordRestClient(config); return new DiscordRestClient(config);
}); });


+ 3
- 3
src/Discord.Net.Rest/Net/HttpClientFactoryClientProvider.cs View File

@@ -8,17 +8,17 @@ using System.Threading.Tasks;


namespace Discord.Rest.Net namespace Discord.Rest.Net
{ {
public class HttpFactoryRestClientProvider
public class HttpClientFactoryRestClientProvider
{ {
public readonly RestClientProvider Instance; public readonly RestClientProvider Instance;


private readonly IHttpClientFactory _httpClientFactory; private readonly IHttpClientFactory _httpClientFactory;


public HttpFactoryRestClientProvider(IHttpClientFactory httpClientFactory)
public HttpClientFactoryRestClientProvider(IHttpClientFactory httpClientFactory)
{ {
_httpClientFactory = httpClientFactory; _httpClientFactory = httpClientFactory;


Instance = url => new HttpClientFactoryClient(url, _httpClientFactory.CreateClient("HttpFactoryRestClientProvider"), useProxy: false);
Instance = url => new HttpClientFactoryRestClient(url, _httpClientFactory.CreateClient("HttpClientFactoryRestClientProvider"), useProxy: false);
} }






src/Discord.Net.Rest/Net/HttpClientFactoryClient.cs → src/Discord.Net.Rest/Net/HttpClientFactoryRestClient.cs View File

@@ -14,7 +14,7 @@ using System.Threading.Tasks;


namespace Discord.Rest.Net namespace Discord.Rest.Net
{ {
internal sealed class HttpClientFactoryClient : IRestClient, IDisposable
internal sealed class HttpClientFactoryRestClient : IRestClient, IDisposable
{ {
private const int HR_SECURECHANNELFAILED = -2146233079; private const int HR_SECURECHANNELFAILED = -2146233079;


@@ -24,7 +24,7 @@ namespace Discord.Rest.Net
private CancellationToken _cancelToken; private CancellationToken _cancelToken;
private bool _isDisposed; private bool _isDisposed;


public HttpClientFactoryClient(string baseUrl, HttpClient httpClient, bool useProxy = false)
public HttpClientFactoryRestClient(string baseUrl, HttpClient httpClient, bool useProxy = false)
{ {
_baseUrl = baseUrl; _baseUrl = baseUrl;
//this client would be given to use through DI. The advantage would be that it would be managed by DI, and no socket Exhaustation possible. //this client would be given to use through DI. The advantage would be that it would be managed by DI, and no socket Exhaustation possible.

Loading…
Cancel
Save