using DysonNetwork.Sphere; using DysonNetwork.Sphere.Startup; using Microsoft.EntityFrameworkCore; using tusdotnet.Stores; using MagicOnion.Client; using DysonNetwork.Shared.Services; using Grpc.Net.Client; var builder = WebApplication.CreateBuilder(args); // Configure Kestrel and server options builder.ConfigureAppKestrel(); // Add metrics and telemetry builder.Services.AddAppMetrics(); // Add application services builder.Services.AddAppServices(builder.Configuration); builder.Services.AddAppRateLimiting(); builder.Services.AddAppAuthentication(); builder.Services.AddAppSwagger(); // Add gRPC services builder.Services.AddGrpc(); // Configure MagicOnion client for IAccountService builder.Services.AddSingleton(provider => { var passServiceUrl = builder.Configuration["PassService:Url"]; if (string.IsNullOrEmpty(passServiceUrl)) { throw new InvalidOperationException("PassService:Url configuration is missing."); } var channel = GrpcChannel.ForAddress(passServiceUrl); return MagicOnionClient.Create(channel); }); // Configure MagicOnion client for IPublisherService builder.Services.AddSingleton(provider => { var passServiceUrl = builder.Configuration["PassService:Url"]; if (string.IsNullOrEmpty(passServiceUrl)) { throw new InvalidOperationException("PassService:Url configuration is missing."); } var channel = GrpcChannel.ForAddress(passServiceUrl); return MagicOnionClient.Create(channel); }); // Configure MagicOnion client for ICustomAppService builder.Services.AddSingleton(provider => { var passServiceUrl = builder.Configuration["PassService:Url"]; if (string.IsNullOrEmpty(passServiceUrl)) { throw new InvalidOperationException("PassService:Url configuration is missing."); } var channel = GrpcChannel.ForAddress(passServiceUrl); return MagicOnionClient.Create(channel); }); // Add file storage builder.Services.AddAppFileStorage(builder.Configuration); // Add flush handlers and websocket handlers builder.Services.AddAppFlushHandlers(); // Add business services builder.Services.AddAppBusinessServices(builder.Configuration); // Add scheduled jobs builder.Services.AddAppScheduledJobs(); var app = builder.Build(); // Run database migrations using (var scope = app.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService(); await db.Database.MigrateAsync(); } // Get the TusDiskStore instance var tusDiskStore = app.Services.GetRequiredService(); // Configure application middleware pipeline app.ConfigureAppMiddleware(builder.Configuration, tusDiskStore); // Remove direct gRPC service mappings for Pass services // app.MapGrpcService(); // app.MapGrpcService(); app.Run();