persistence/Persistence.Client/PersistenceClientFactory.cs

33 lines
948 B
C#
Raw Normal View History

using System.Text.Json;
using Microsoft.Extensions.Configuration;
2024-11-21 14:50:36 +05:00
using Persistence.Client.Helpers;
using Refit;
2024-11-21 14:50:36 +05:00
namespace Persistence.Client
{
/// <summary>
/// Фабрика клиентов для доступа к Persistence - сервису
/// </summary>
public class PersistenceClientFactory
2024-11-21 14:50:36 +05:00
{
private static readonly JsonSerializerOptions JsonSerializerOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true
};
private static readonly RefitSettings RefitSettings = new(new SystemTextJsonContentSerializer(JsonSerializerOptions));
private HttpClient httpClient;
public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IConfiguration configuration)
2024-11-21 14:50:36 +05:00
{
this.httpClient = httpClientFactory.CreateClient();
2024-11-21 14:50:36 +05:00
httpClient.Authorize(configuration);
2024-11-21 14:50:36 +05:00
}
public T GetClient<T>()
2024-11-21 14:50:36 +05:00
{
return RestService.For<T>(httpClient, RefitSettings);
2024-11-21 14:50:36 +05:00
}
}
}