// ───────────────────────────────────────────────────────────────────────────── // Shared service registrations — identical in both hosting modes. // Never changes regardless of which block is active below. // ───────────────────────────────────────────────────────────────────────────── using Microsoft.Identity.Web; using Registration.Data; void ConfigureServices(IServiceCollection services, IConfiguration config) { // JWT authentication — Entra External ID (CIAM) // Validates Bearer tokens issued by PositiveSpendClients.ciamlogin.com. // Config keys: AzureAd:Instance / TenantId / ClientId / Audience // In ASP.NET Core mode: appsettings.json + env vars (AzureAd__*) // In Functions mode: local.settings.json AzureAd section (dev only) services.AddAuthentication() .AddMicrosoftIdentityWebApi(config.GetSection("AzureAd")); services.AddAuthorization(); // Data layer — swap here to flip between mock (no DB) and real DB. // MockDataService: no connection string required, seeds 4 test applicants. // SqlDataService: requires ConnectionStrings:Sql → dbRegistration on 10.10.99.212 // Calls dbo.spRegistration with @action/@rqst/@resp OUTPUT pattern. services.AddSingleton(); services.AddSingleton(); // ── swap data layer here if needed ────────────────────────────────────── // services.AddSingleton(); } // ═════════════════════════════════════════════════════════════════════════════ // SWAP: ASP.NET Core host ◄ ACTIVE // Running in docker-compose as registration:8080 behind nginx / Gateway. // Dockerfile: mcr.microsoft.com/dotnet/aspnet:8.0 ← matches this mode. // ═════════════════════════════════════════════════════════════════════════════ var builder = WebApplication.CreateBuilder(args); ConfigureServices(builder.Services, builder.Configuration); builder.Services.AddControllers(); // CORS — reads CORS:AllowedOrigins from appsettings.json or env var CORS__AllowedOrigins. // Comma-separated list. Matches the value already in docker-compose .env: // CORS__AllowedOrigins=https://client.positivespend.com,https://portal.positivespend.com,... builder.Services.AddCors(options => options.AddDefaultPolicy(policy => policy.WithOrigins( (builder.Configuration["CORS:AllowedOrigins"] ?? "") .Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ) .AllowAnyHeader() .AllowAnyMethod())); var app = builder.Build(); app.UseCors(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); await app.RunAsync(); // ═════════════════════════════════════════════════════════════════════════════ // SWAP: Azure Functions host ◄ INACTIVE — uncomment to restore // Active when deployed to Azure Functions or running via: func start // Also update RegistrationFunctions.cs and Registration.csproj. // ═════════════════════════════════════════════════════════════════════════════ // using Microsoft.Azure.Functions.Worker; // // var host = new HostBuilder() // .ConfigureFunctionsWebApplication() // .ConfigureServices((ctx, services) => // { // services.AddApplicationInsightsTelemetryWorkerService(); // services.ConfigureFunctionsApplicationInsights(); // ConfigureServices(services, ctx.Configuration); // }) // .Build(); // // host.Run(); // ─────────────────────────────────────────────────────────────────────────────