♻️ No idea what happended
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
<PackageReference Include="dotnet-etcd" Version="8.0.1" />
|
||||
<PackageReference Include="MagicOnion.Abstractions" Version="7.0.5" />
|
||||
<PackageReference Include="MagicOnion.Client" Version="7.0.5" />
|
||||
<PackageReference Include="MagicOnion.Server" Version="7.0.5" />
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ using System.Net;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace DysonNetwork.Shared.Startup;
|
||||
|
||||
@@ -30,7 +32,17 @@ public static class ApplicationConfiguration
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers().RequireRateLimiting("fixed");
|
||||
app.MapStaticAssets().RequireRateLimiting("fixed");
|
||||
|
||||
try
|
||||
{
|
||||
app.MapStaticAssets().RequireRateLimiting("fixed");
|
||||
}
|
||||
catch (InvalidOperationException) when (app.Environment.IsDevelopment())
|
||||
{
|
||||
// Ignore missing static assets in development
|
||||
app.Logger.LogWarning("Static assets not found. Skipping static assets mapping.");
|
||||
}
|
||||
|
||||
app.MapRazorPages().RequireRateLimiting("fixed");
|
||||
|
||||
return app;
|
||||
|
||||
Reference in New Issue
Block a user