Files
voltsrage 24f45851e9
CI / frontend (push) Canceled after 0s
CI / backend (push) Canceled after 8m32s
feature: In-App Simulation Runner (Backend)
2026-08-06 01:52:53 +08:00

27 lines
925 B
C#

using Microsoft.Extensions.Options;
using VigilCare.Simulation;
public sealed class SimulationClientFactory : ISimulationClientFactory
{
private readonly IHttpClientFactory _http;
private readonly SimulationOptions _options;
public SimulationClientFactory(IHttpClientFactory http, IOptions<SimulationOptions> options)
{
_http = http;
_options = options.Value;
}
public async Task<VigilCareApiClient> CreateAsync(CancellationToken ct = default)
{
if (string.IsNullOrWhiteSpace(_options.RunnerPassword))
throw new InvalidOperationException(
"Simulation:RunnerPassword is required when Simulation:Enabled is true.");
var http = _http.CreateClient("simulation-loopback");
var client = new VigilCareApiClient(http);
await client.LoginAsync(_options.RunnerUsername, _options.RunnerPassword);
return client;
}
}