Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inject contextAccessor #27

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ATI.Services.Consul/ConsulMetricsHttpClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using ATI.Services.Common.Options;
using ATI.Services.Common.Serializers;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using NLog;
Expand All @@ -34,7 +35,8 @@
BaseServiceOptions serviceOptions,
string adapterName,
IHttpClientFactory httpClientFactory,
MetricsFactory metricsFactory,
MetricsFactory metricsFactory,
IHttpContextAccessor httpContextAccessor,
JsonSerializerSettings newtonsoftSettings = null,
JsonSerializerOptions systemTextJsonOptions = null)
{
Expand All @@ -59,7 +61,7 @@
_clientConfig.Headers.TryAdd(header.Key, header.Value);
}

_clientWrapper = new MetricsHttpClientWrapper(_clientConfig, httpClientFactory);
_clientWrapper = new MetricsHttpClientWrapper(_clientConfig, httpClientFactory, httpContextAccessor);
}

public void SetSerializer(JsonSerializerSettings newtonsoftSettings)
Expand Down Expand Up @@ -358,13 +360,14 @@
/// It must be used via DI, add it by .AddConsulMetricsHttpClientWrappers()
/// </summary>
[PublicAPI]
public class ConsulMetricsHttpClientWrapper<T> : ConsulMetricsHttpClientWrapper

Check warning on line 363 in ATI.Services.Consul/ConsulMetricsHttpClientWrapper.cs

View workflow job for this annotation

GitHub Actions / build

'ConsulMetricsHttpClientWrapper' is obsolete: 'Use HttpClientFactory instead'

Check warning on line 363 in ATI.Services.Consul/ConsulMetricsHttpClientWrapper.cs

View workflow job for this annotation

GitHub Actions / build

'ConsulMetricsHttpClientWrapper' is obsolete: 'Use HttpClientFactory instead'
where T : BaseServiceOptions
{
public ConsulMetricsHttpClientWrapper(
IOptions<T> serviceOptions,
IHttpClientFactory httpClientFactory,
MetricsFactory metricsFactory) : base(serviceOptions.Value, serviceOptions.Value.ConsulName, httpClientFactory, metricsFactory)
MetricsFactory metricsFactory,
IHttpContextAccessor httpContextAccessor) : base(serviceOptions.Value, serviceOptions.Value.ConsulName, httpClientFactory, metricsFactory, httpContextAccessor)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static IServiceCollection AddConsulMetricsHttpClientWrappers(this IServic
// Add IHttpClientFactory for ConsulMetricsHttpClientWrapper<>
services.AddHttpClient();
services.AddSingleton(typeof(ConsulMetricsHttpClientWrapper<>));
services.AddHttpContextAccessor();
return services;
}
}
Loading