ec4c8fab87
Move configuration options from Core/DataAccess/DataSync/ExcelIO to dedicated Options folders within each project for better organization. Update all references and tests accordingly.
83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using JdeScoping.Api;
|
|
using JdeScoping.Core.Interfaces;
|
|
using JdeScoping.DataAccess.Options;
|
|
using JdeScoping.DataSync.Options;
|
|
using JdeScoping.ExcelIO.Options;
|
|
using JdeScoping.Infrastructure.Options;
|
|
using JdeScoping.Database;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Windows Service support (no-op on non-Windows)
|
|
builder.Host.UseWindowsService();
|
|
|
|
// Run database migrations (skip in Testing environment)
|
|
if (!builder.Environment.IsEnvironment("Testing"))
|
|
{
|
|
var migrator = new DatabaseMigrator(builder.Configuration);
|
|
var migrationResult = migrator.Migrate();
|
|
|
|
if (!migrationResult.Successful)
|
|
{
|
|
Console.WriteLine($"Database migration failed: {migrationResult.Error?.Message}");
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
// ASP.NET Core services
|
|
builder.Services.AddRazorPages();
|
|
|
|
// Module registration (in dependency order)
|
|
builder.Services
|
|
.AddDataAccess(builder.Configuration) // 1. Database access + search processing
|
|
.AddInfrastructure(builder.Configuration) // 2. Infrastructure (JDE/CMS/Auth)
|
|
.AddDataSyncServices(builder.Configuration) // 3. Data sync background service
|
|
.AddExcelIO(builder.Configuration) // 4. Result export
|
|
.AddWebApi(builder.Configuration); // 5. Web API (controllers, auth, SignalR)
|
|
|
|
var app = builder.Build();
|
|
|
|
// Startup validation - verify critical services are registered
|
|
ValidateServices(app.Services);
|
|
|
|
// Configure the HTTP request pipeline
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseWebAssemblyDebugging();
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
app.UseBlazorFrameworkFiles();
|
|
app.UseRouting();
|
|
|
|
// Configure Web API middleware (authentication, authorization, controllers, SignalR hub)
|
|
app.UseWebApi();
|
|
|
|
app.MapRazorPages();
|
|
app.MapFallbackToFile("index.html");
|
|
|
|
app.Run();
|
|
|
|
return 0;
|
|
|
|
// Validates that critical services are properly registered
|
|
static void ValidateServices(IServiceProvider services)
|
|
{
|
|
using var scope = services.CreateScope();
|
|
var provider = scope.ServiceProvider;
|
|
|
|
// Validate Options classes are bound
|
|
_ = provider.GetRequiredService<IOptions<DataAccessOptions>>();
|
|
_ = provider.GetRequiredService<IOptions<DataSyncOptions>>();
|
|
_ = provider.GetRequiredService<IOptions<ExcelExportOptions>>();
|
|
_ = provider.GetRequiredService<IOptions<SearchProcessingOptions>>();
|
|
_ = provider.GetRequiredService<IOptions<DataSourceOptions>>();
|
|
|
|
// Validate data source services
|
|
_ = provider.GetRequiredService<IJdeDataSource>();
|
|
_ = provider.GetRequiredService<ICmsDataSource>();
|
|
|
|
Console.WriteLine("Service validation completed successfully.");
|
|
}
|