persistence/Persistence.Client/PersistenceClientFactory.cs

31 lines
867 B
C#

using System.Text.Json;
using Microsoft.Extensions.Configuration;
using Persistence.Client.Helpers;
using Persistence.Models.Configurations;
using Refit;
namespace Persistence.Client
{
public class PersistenceClientFactory
{
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)
{
this.httpClient = httpClientFactory.CreateClient();
httpClient.Authorize(configuration);
}
public T GetClient<T>()
{
return RestService.For<T>(httpClient, RefitSettings);
}
}
}