Files
Swarm/DysonNetwork.Sphere/Program.cs
2025-07-08 23:55:31 +08:00

93 lines
2.9 KiB
C#

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<IAccountService>(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<IAccountService>(channel);
});
// Configure MagicOnion client for IPublisherService
builder.Services.AddSingleton<IPublisherService>(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<IPublisherService>(channel);
});
// Configure MagicOnion client for ICustomAppService
builder.Services.AddSingleton<ICustomAppService>(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<ICustomAppService>(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<AppDatabase>();
await db.Database.MigrateAsync();
}
// Get the TusDiskStore instance
var tusDiskStore = app.Services.GetRequiredService<TusDiskStore>();
// Configure application middleware pipeline
app.ConfigureAppMiddleware(builder.Configuration, tusDiskStore);
// Remove direct gRPC service mappings for Pass services
// app.MapGrpcService<DysonNetwork.Pass.Auth.AuthGrpcService>();
// app.MapGrpcService<DysonNetwork.Pass.Account.AccountGrpcService>();
app.Run();