2024-11-25 10:09:38 +05:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2024-11-21 14:50:36 +05:00
|
|
|
|
using Persistence.Client.Helpers;
|
2024-11-25 10:09:38 +05:00
|
|
|
|
using Persistence.Models.Configurations;
|
|
|
|
|
using Refit;
|
2024-11-21 14:50:36 +05:00
|
|
|
|
|
|
|
|
|
namespace Persistence.Client
|
|
|
|
|
{
|
2024-11-25 10:09:38 +05:00
|
|
|
|
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));
|
2024-11-25 10:09:38 +05:00
|
|
|
|
private HttpClient httpClient;
|
|
|
|
|
public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IConfiguration configuration)
|
2024-11-21 14:50:36 +05:00
|
|
|
|
{
|
2024-11-25 10:09:38 +05:00
|
|
|
|
this.httpClient = httpClientFactory.CreateClient();
|
2024-11-21 14:50:36 +05:00
|
|
|
|
|
2024-11-25 10:09:38 +05:00
|
|
|
|
httpClient.Authorize(configuration);
|
2024-11-21 14:50:36 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 10:09:38 +05:00
|
|
|
|
public T GetClient<T>()
|
2024-11-21 14:50:36 +05:00
|
|
|
|
{
|
2024-11-25 10:09:38 +05:00
|
|
|
|
return RestService.For<T>(httpClient, RefitSettings);
|
2024-11-21 14:50:36 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|