44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using LSFE.MobApp.Contracts;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LSFE.MobApp.Services
|
|
{
|
|
public class ApiClientFactory : IApiClientFactory
|
|
{
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly string _baseUrl;
|
|
|
|
public ApiClientFactory(IHttpClientFactory httpClientFactory, IConfiguration configuration)
|
|
{
|
|
_httpClientFactory = httpClientFactory;
|
|
_baseUrl = configuration["ApiSettings:BaseUrl"];
|
|
}
|
|
//DEV ONLY MUST BE REVERT TO PROD ONCE CREATION
|
|
public IApiClient<T> CreateClient<T>(string endpoint) where T : class
|
|
{
|
|
var httpClient = _httpClientFactory.CreateClient("ApiClient");
|
|
httpClient.BaseAddress = new Uri(_baseUrl);
|
|
|
|
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
|
|
|
return new ApiClient<T>(httpClient, endpoint);
|
|
}
|
|
}
|
|
}
|
|
//PROD
|
|
/* public IApiClient<T> CreateClient<T>(string endpoint) where T : class
|
|
{
|
|
var httpClient = _httpClientFactory.CreateClient();
|
|
httpClient.BaseAddress = new Uri(_baseUrl);
|
|
|
|
// Add any common headers here
|
|
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
|
|
|
return new ApiClient<T>(httpClient, endpoint);
|
|
}*/ |