6593acbc20
Some checks failed
Unit tests / test (push) Failing after 1m1s
Работает пока только для ChangeLog
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
|
using DD.Persistence.Client.Helpers;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Refit;
|
|
using System.Text.Json;
|
|
|
|
namespace DD.Persistence.Client;
|
|
|
|
/// <summary>
|
|
/// Фабрика, которая создает refit-клиентов
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public class RefitClientFactory<T> : IRefitClientFactory<T> where T : IRefitClient
|
|
{
|
|
private HttpClient client;
|
|
private RefitSettings refitSettings;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public RefitClientFactory(IConfiguration configuration)
|
|
{
|
|
this.client = new HttpClient();
|
|
|
|
var baseUrl = configuration.GetSection("ClientUrl").Get<string>()!;
|
|
client.BaseAddress = new Uri(baseUrl);
|
|
client.Authorize(configuration);
|
|
|
|
JsonSerializerOptions JsonSerializerOptions = new()
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
PropertyNameCaseInsensitive = true
|
|
};
|
|
refitSettings = new(new SystemTextJsonContentSerializer(JsonSerializerOptions));
|
|
}
|
|
/// <summary>
|
|
/// создание клиента
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public T Create()
|
|
{
|
|
|
|
|
|
return RestService.For<T>(client, refitSettings);
|
|
}
|
|
}
|