76 lines
4.4 KiB
C#
76 lines
4.4 KiB
C#
using Microsoft.Azure.Functions.Worker; // ← SWAP: remove for AspNetCore
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Identity.Web;
|
|
using Registration.Data;
|
|
using Registration.Mock;
|
|
|
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
// Shared service registrations — identical in both hosting modes.
|
|
// Never changes regardless of which block is active below.
|
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
void ConfigureServices(IServiceCollection services, IConfiguration config)
|
|
{
|
|
// JWT authentication — Entra External ID (CIAM)
|
|
// Validates Bearer tokens issued by usimclients.ciamlogin.com.
|
|
// AzureAd config comes from local.settings.json (Functions) or
|
|
// appsettings.json / environment variables (AspNetCore).
|
|
services.AddAuthentication()
|
|
.AddMicrosoftIdentityWebApi(config.GetSection("AzureAd"));
|
|
|
|
services.AddAuthorization();
|
|
|
|
// Data layer — swap between MockDataService (no DB) and SqlDataService (dbRegistration).
|
|
// MockDataService: no connection string required, seeds 4 test applicants.
|
|
// SqlDataService: requires ConnectionStrings:Sql pointed at dbRegistration.
|
|
// Calls dbo.spRegistration with @action/@rqst/@resp OUTPUT pattern.
|
|
services.AddSingleton<SqlService>();
|
|
services.AddSingleton<IRegistrationDataService, SqlDataService>();
|
|
// ── swap data layer here if needed ──────────────────────────────────────
|
|
// services.AddSingleton<IRegistrationDataService, MockDataService>();
|
|
}
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════════
|
|
// SWAP: Azure Functions host
|
|
// Active when deployed to Azure Functions or running via: func start
|
|
// ═════════════════════════════════════════════════════════════════════════════
|
|
var host = new HostBuilder()
|
|
.ConfigureFunctionsWebApplication()
|
|
.ConfigureServices((ctx, services) =>
|
|
{
|
|
services.AddApplicationInsightsTelemetryWorkerService();
|
|
services.ConfigureFunctionsApplicationInsights();
|
|
ConfigureServices(services, ctx.Configuration);
|
|
})
|
|
.Build();
|
|
|
|
host.Run();
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════════
|
|
// SWAP: ASP.NET Core host
|
|
// Active when running in podman-compose or dotnet run (self-hosted).
|
|
// Also update RegistrationFunctions.cs and Registration.csproj.
|
|
// ═════════════════════════════════════════════════════════════════════════════
|
|
// var builder = WebApplication.CreateBuilder(args);
|
|
//
|
|
// ConfigureServices(builder.Services, builder.Configuration);
|
|
// builder.Services.AddControllers();
|
|
//
|
|
// // CORS — replace with actual client origin in production
|
|
// builder.Services.AddCors(options => options.AddDefaultPolicy(policy =>
|
|
// policy.WithOrigins(
|
|
// builder.Configuration["Cors:AllowedOrigin"] ?? "http://localhost:3001"
|
|
// )
|
|
// .AllowAnyHeader()
|
|
// .AllowAnyMethod()));
|
|
//
|
|
// var app = builder.Build();
|
|
//
|
|
// app.UseCors();
|
|
// app.UseAuthentication();
|
|
// app.UseAuthorization();
|
|
// app.MapControllers();
|
|
//
|
|
// await app.RunAsync();
|
|
// ───────────────────────────────────────────────────────────────────────────── |