39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System;
|
|
using Microsoft.Extensions.Http;
|
|
using Microsoft.Extensions.Options;
|
|
using StellaOps.Cryptography.Plugin.SimRemote;
|
|
|
|
namespace StellaOps.Cryptography.DependencyInjection;
|
|
|
|
internal sealed class SimRemoteHttpClientOptionsConfiguration : IConfigureNamedOptions<HttpClientFactoryOptions>
|
|
{
|
|
private readonly IOptionsMonitor<SimRemoteProviderOptions> _options;
|
|
|
|
public SimRemoteHttpClientOptionsConfiguration(IOptionsMonitor<SimRemoteProviderOptions> options)
|
|
{
|
|
_options = options ?? throw new ArgumentNullException(nameof(options));
|
|
}
|
|
|
|
public void Configure(HttpClientFactoryOptions options)
|
|
{
|
|
Configure(Options.DefaultName, options);
|
|
}
|
|
|
|
public void Configure(string? name, HttpClientFactoryOptions options)
|
|
{
|
|
if (!string.Equals(name, CryptoHttpClientNames.SimRemote, StringComparison.Ordinal))
|
|
{
|
|
return;
|
|
}
|
|
|
|
options.HttpClientActions.Add(client =>
|
|
{
|
|
var current = _options.CurrentValue;
|
|
if (!string.IsNullOrWhiteSpace(current.BaseAddress))
|
|
{
|
|
client.BaseAddress = new Uri(current.BaseAddress);
|
|
}
|
|
});
|
|
}
|
|
}
|