Switched Azure Function to ASP.net
Some checks failed
CI Build and Deploy / build (push) Has been cancelled
Some checks failed
CI Build and Deploy / build (push) Has been cancelled
This commit is contained in:
@@ -1,36 +1,76 @@
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
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((context, services) =>
|
||||
.ConfigureServices((ctx, services) =>
|
||||
{
|
||||
services.AddApplicationInsightsTelemetryWorkerService();
|
||||
services.ConfigureFunctionsApplicationInsights();
|
||||
|
||||
// =============================================================
|
||||
// JWT Authentication — Entra External ID (CIAM)
|
||||
// Validates Bearer tokens issued by usimclients.ciamlogin.com.
|
||||
// AzureAd config is in local.settings.json (dev) or Function App
|
||||
// Configuration (production) using AzureAd__ prefix.
|
||||
// =============================================================
|
||||
services.AddAuthentication()
|
||||
.AddMicrosoftIdentityWebApi(context.Configuration.GetSection("AzureAd"));
|
||||
|
||||
services.AddAuthorization();
|
||||
|
||||
// =============================================================
|
||||
// Data layer — SqlDataService backed by dbRegistration.
|
||||
// Connection string: ConnectionStrings:Sql in local.settings.json
|
||||
// or the "Sql" connection string in Function App Configuration.
|
||||
// =============================================================
|
||||
services.AddSingleton<SqlService>();
|
||||
services.AddSingleton<IRegistrationDataService, SqlDataService>();
|
||||
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();
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
Reference in New Issue
Block a user