using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using StackExchange.Redis; 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.Auth.ServerIntegration; using StellaOps.BinaryIndex.WebService.Telemetry; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // Configure options builder.Services.Configure( builder.Configuration.GetSection(ResolutionServiceOptions.SectionName)); builder.Services.AddSingleton, ResolutionCacheOptionsValidator>(); builder.Services.AddOptions() .Bind(builder.Configuration.GetSection(ResolutionCacheOptions.SectionName)) .ValidateOnStart(); // Add Redis/Valkey connection var redisConnectionString = builder.Configuration.GetConnectionString("Redis") ?? "localhost:6379"; builder.Services.AddSingleton(_ => ConnectionMultiplexer.Connect(redisConnectionString)); // Add services builder.Services.TryAddSingleton(TimeProvider.System); builder.Services.TryAddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(sp => new CachedResolutionService( sp.GetRequiredService(), sp.GetRequiredService(), sp.GetRequiredService>(), sp.GetRequiredService>(), sp.GetRequiredService(), sp.GetRequiredService>())); // 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"); builder.Services.AddStellaOpsCors(builder.Environment, builder.Configuration); builder.TryAddStellaOpsLocalBinding("binaryindex"); var app = builder.Build(); app.LogStellaOpsLocalHostname("binaryindex"); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseStellaOpsCors(); app.UseHttpsRedirection(); app.UseResolutionRateLimiting(); app.UseAuthorization(); app.MapControllers(); app.MapHealthChecks("/health"); app.Run();