using Microsoft.Extensions.Logging;
namespace System.Net.Http
{
///
/// 通用 工厂
///
public abstract class GeneralHttpClientFactory
{
protected readonly ILogger logger;
protected readonly IHttpPlatformHelper http_helper;
readonly IHttpClientFactory _clientFactory;
public GeneralHttpClientFactory(
ILogger logger,
IHttpPlatformHelper http_helper,
IHttpClientFactory clientFactory)
{
this.logger = logger;
this.http_helper = http_helper;
_clientFactory = clientFactory;
}
///
/// 用于 中传递的 name
/// 如果为 则调用
/// 默认值为
///
protected virtual string? ClientName { get; }
protected virtual HttpClient CreateClient()
{
#if DEBUG
logger.LogDebug("CreateClient, name: {0}", ClientName);
#endif
if (ClientName == null)
{
return _clientFactory.CreateClient();
}
else
{
return _clientFactory.CreateClient(ClientName);
}
}
}
}