From 481f13021c8379355ed137cbda7909124bef636d Mon Sep 17 00:00:00 2001 From: Ionite Date: Mon, 31 Jul 2023 17:47:50 -0400 Subject: [PATCH] Add ApiFactory --- StabilityMatrix.Core/Api/ApiFactory.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 StabilityMatrix.Core/Api/ApiFactory.cs diff --git a/StabilityMatrix.Core/Api/ApiFactory.cs b/StabilityMatrix.Core/Api/ApiFactory.cs new file mode 100644 index 00000000..30289f6b --- /dev/null +++ b/StabilityMatrix.Core/Api/ApiFactory.cs @@ -0,0 +1,21 @@ +using Refit; + +namespace StabilityMatrix.Core.Api; + +public class ApiFactory +{ + private readonly IHttpClientFactory httpClientFactory; + public RefitSettings? RefitSettings { get; init; } + + public ApiFactory(IHttpClientFactory httpClientFactory) + { + this.httpClientFactory = httpClientFactory; + } + + public T CreateRefitClient(Uri baseAddress) + { + var httpClient = httpClientFactory.CreateClient(nameof(T)); + httpClient.BaseAddress = baseAddress; + return RestService.For(httpClient, RefitSettings); + } +}