♻️ No idea what happended
This commit is contained in:
@@ -12,15 +12,16 @@ namespace DysonNetwork.Shared.Etcd
|
||||
{
|
||||
public static IServiceCollection AddEtcdService(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var etcdConnectionString = configuration.GetConnectionString("Etcd");
|
||||
services.AddSingleton<IEtcdService>(new EtcdService(etcdConnectionString!));
|
||||
var connectionString = configuration["ConnectionStrings:Etcd"];
|
||||
if (connectionString is null) throw new ArgumentNullException(nameof(connectionString));
|
||||
services.AddSingleton<IEtcdService>(new EtcdService(connectionString!));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddMagicOnionService<TService>(this IServiceCollection services)
|
||||
public static IServiceCollection AddRemoteService<TService>(this IServiceCollection services)
|
||||
where TService : class, MagicOnion.IService<TService>
|
||||
{
|
||||
services.AddSingleton(serviceProvider =>
|
||||
services.AddSingleton<TService>(serviceProvider =>
|
||||
{
|
||||
var etcdService = serviceProvider.GetRequiredService<IEtcdService>();
|
||||
var serviceName = typeof(TService).Name.TrimStart('I'); // Convention: IMyService -> MyService
|
||||
@@ -28,10 +29,8 @@ namespace DysonNetwork.Shared.Etcd
|
||||
// Synchronously wait for service discovery (or handle asynchronously if preferred)
|
||||
var endpoints = etcdService.DiscoverServicesAsync(serviceName).GetAwaiter().GetResult();
|
||||
|
||||
if (!endpoints.Any())
|
||||
{
|
||||
if (endpoints.Count == 0)
|
||||
throw new InvalidOperationException($"No endpoints found for MagicOnion service: {serviceName}");
|
||||
}
|
||||
|
||||
// For simplicity, use the first discovered endpoint
|
||||
var endpoint = endpoints.First();
|
||||
@@ -39,7 +38,7 @@ namespace DysonNetwork.Shared.Etcd
|
||||
var channel = GrpcChannel.ForAddress(endpoint);
|
||||
return MagicOnionClient.Create<TService>(channel);
|
||||
});
|
||||
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user