Browse Source

Add ApiFactory option for custom refit settings

pull/495/head
Ionite 9 months ago
parent
commit
942013673a
No known key found for this signature in database
  1. 10
      StabilityMatrix.Core/Api/ApiFactory.cs
  2. 6
      StabilityMatrix.Core/Api/IApiFactory.cs

10
StabilityMatrix.Core/Api/ApiFactory.cs

@ -6,7 +6,7 @@ public class ApiFactory : IApiFactory
{
private readonly IHttpClientFactory httpClientFactory;
public RefitSettings? RefitSettings { get; init; }
public ApiFactory(IHttpClientFactory httpClientFactory)
{
this.httpClientFactory = httpClientFactory;
@ -18,4 +18,12 @@ public class ApiFactory : IApiFactory
httpClient.BaseAddress = baseAddress;
return RestService.For<T>(httpClient, RefitSettings);
}
public T CreateRefitClient<T>(Uri baseAddress, RefitSettings refitSettings)
{
var httpClient = httpClientFactory.CreateClient(nameof(T));
httpClient.BaseAddress = baseAddress;
return RestService.For<T>(httpClient, refitSettings);
}
}

6
StabilityMatrix.Core/Api/IApiFactory.cs

@ -1,6 +1,10 @@
namespace StabilityMatrix.Core.Api;
using Refit;
namespace StabilityMatrix.Core.Api;
public interface IApiFactory
{
public T CreateRefitClient<T>(Uri baseAddress);
public T CreateRefitClient<T>(Uri baseAddress, RefitSettings refitSettings);
}

Loading…
Cancel
Save