🔨 Reconfigured to use new discovery

This commit is contained in:
2025-12-13 17:38:49 +08:00
parent bc3d030a1e
commit 42082fbefa
17 changed files with 138 additions and 18 deletions

View File

@@ -0,0 +1,31 @@
using DysonNetwork.Shared.Registry;
using Microsoft.Extensions.Configuration;
using System.Text;
using System.Text.Json;
namespace DysonNetwork.Shared.Configurator;
public class ConfigureService(ServiceRegistrar registrar)
{
private readonly ServiceRegistrar _registrar = registrar;
public async Task<JsonDocument> GetConfigurationsAsync()
{
var instance = await _registrar.GetServiceInstanceAsync("config", "http");
using var client = new HttpClient();
var response = await client.GetStringAsync($"http://{instance}/config");
var json = JsonDocument.Parse(response);
return json;
}
public async Task ConfigureAppAsync(IConfigurationBuilder builder)
{
var configs = await GetConfigurationsAsync();
if (configs.RootElement.TryGetProperty("connection_strings", out var csElement))
{
var csJson = csElement.ToString();
var stream = new MemoryStream(Encoding.UTF8.GetBytes(csJson));
builder.AddJsonStream(stream);
}
}
}