using FictionArchive.Common.Extensions; using FictionArchive.Service.Shared; using FictionArchive.Service.Shared.Extensions; using FictionArchive.Service.Shared.Services.EventBus.Implementations; using FictionArchive.Service.UserNovelDataService.GraphQL; using FictionArchive.Service.UserNovelDataService.Services; namespace FictionArchive.Service.UserNovelDataService; public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); var isSchemaExport = SchemaExportDetector.IsSchemaExportMode(args); builder.AddLocalAppsettings(); builder.Services.AddMemoryCache(); builder.Services.AddHealthChecks(); #region Event Bus if (!isSchemaExport) { builder.Services.AddRabbitMQ(opt => { builder.Configuration.GetSection("RabbitMQ").Bind(opt); }); } #endregion #region GraphQL builder.Services.AddDefaultGraphQl() .AddAuthorization(); #endregion #region Database builder.Services.RegisterDbContext( builder.Configuration.GetConnectionString("DefaultConnection"), skipInfrastructure: isSchemaExport); #endregion // Authentication & Authorization builder.Services.AddOidcAuthentication(builder.Configuration); builder.Services.AddFictionArchiveAuthorization(); var app = builder.Build(); // Update database (skip in schema export mode) if (!isSchemaExport) { using var scope = app.Services.CreateScope(); var dbContext = scope.ServiceProvider.GetRequiredService(); dbContext.UpdateDatabase(); } app.UseHttpsRedirection(); app.MapHealthChecks("/healthz"); app.UseAuthentication(); app.UseAuthorization(); app.MapGraphQL(); app.RunWithGraphQLCommands(args); } }