save progress
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using StellaOps.BinaryIndex.Cache;
|
||||
using StellaOps.BinaryIndex.Core.Resolution;
|
||||
using StellaOps.BinaryIndex.VexBridge;
|
||||
using StellaOps.BinaryIndex.WebService.Middleware;
|
||||
using StellaOps.BinaryIndex.WebService.Services;
|
||||
using StellaOps.BinaryIndex.WebService.Telemetry;
|
||||
using StackExchange.Redis;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -13,8 +19,10 @@ builder.Services.AddSwaggerGen();
|
||||
// Configure options
|
||||
builder.Services.Configure<ResolutionServiceOptions>(
|
||||
builder.Configuration.GetSection(ResolutionServiceOptions.SectionName));
|
||||
builder.Services.Configure<ResolutionCacheOptions>(
|
||||
builder.Configuration.GetSection(ResolutionCacheOptions.SectionName));
|
||||
builder.Services.AddSingleton<IValidateOptions<ResolutionCacheOptions>, ResolutionCacheOptionsValidator>();
|
||||
builder.Services.AddOptions<ResolutionCacheOptions>()
|
||||
.Bind(builder.Configuration.GetSection(ResolutionCacheOptions.SectionName))
|
||||
.ValidateOnStart();
|
||||
|
||||
// Add Redis/Valkey connection
|
||||
var redisConnectionString = builder.Configuration.GetConnectionString("Redis") ?? "localhost:6379";
|
||||
@@ -22,12 +30,29 @@ builder.Services.AddSingleton<IConnectionMultiplexer>(_ =>
|
||||
ConnectionMultiplexer.Connect(redisConnectionString));
|
||||
|
||||
// Add services
|
||||
builder.Services.TryAddSingleton(TimeProvider.System);
|
||||
builder.Services.TryAddSingleton<IRandomSource, SystemRandomSource>();
|
||||
builder.Services.AddSingleton<IResolutionCacheService, ResolutionCacheService>();
|
||||
builder.Services.AddScoped<IResolutionService, ResolutionService>();
|
||||
builder.Services.AddScoped<ResolutionService>();
|
||||
builder.Services.AddScoped<IResolutionService>(sp =>
|
||||
new CachedResolutionService(
|
||||
sp.GetRequiredService<ResolutionService>(),
|
||||
sp.GetRequiredService<IResolutionCacheService>(),
|
||||
sp.GetRequiredService<IOptions<ResolutionCacheOptions>>(),
|
||||
sp.GetRequiredService<IOptions<ResolutionServiceOptions>>(),
|
||||
sp.GetRequiredService<TimeProvider>(),
|
||||
sp.GetRequiredService<ILogger<CachedResolutionService>>()));
|
||||
|
||||
// Add VexBridge
|
||||
builder.Services.AddBinaryVexBridge(builder.Configuration);
|
||||
|
||||
// Add telemetry
|
||||
builder.Services.AddResolutionTelemetry();
|
||||
|
||||
// Add rate limiting
|
||||
builder.Services.AddResolutionRateLimiting(options =>
|
||||
builder.Configuration.GetSection("RateLimiting").Bind(options));
|
||||
|
||||
// Add health checks
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddRedis(redisConnectionString, name: "redis");
|
||||
@@ -42,6 +67,7 @@ if (app.Environment.IsDevelopment())
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseResolutionRateLimiting();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
app.MapHealthChecks("/health");
|
||||
|
||||
Reference in New Issue
Block a user