using Big.Application; using Big.Domain; using Big.Infrastructure; var builder = WebApplication.CreateBuilder(args); // Options bound from configuration (compose sets Flowable__* and Acl__* env vars). builder.Services.AddSingleton(sp => sp.GetRequiredService() .GetSection("Flowable").Get() ?? throw new InvalidOperationException("Missing configuration section 'Flowable'")); builder.Services.AddSingleton(sp => sp.GetRequiredService() .GetSection("Acl").Get() ?? throw new InvalidOperationException("Missing configuration section 'Acl'")); // The in-memory registration store is shared between the submit endpoint and the worker (ADR-0009). builder.Services.AddSingleton(); // The Workflow Client is one type behind two ports (start side + worker side); both resolve to the // same HttpClient-backed implementation — the only code that talks to Flowable (§8.2). builder.Services.AddHttpClient(); builder.Services.AddTransient(sp => sp.GetRequiredService()); builder.Services.AddTransient(sp => sp.GetRequiredService()); builder.Services.AddHttpClient(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); // The hosted external-task job worker polls Flowable and drives OpenZaakAanmaken to completion. builder.Services.AddHostedService(); var app = builder.Build(); app.MapGet("/health", () => "Healthy"); // Submit a registration. The aggregate is created (INGEDIEND) and the registratie process started; // the zaak is opened later, off the request path, by the worker — so this returns 202 Accepted with // a location to read the registration's progress (ADR-0009, eventual consistency). app.MapPost("/registrations", async (SubmitRegistrationRequest body, SubmitRegistration submit, CancellationToken ct) => { var id = await submit.HandleAsync(new SubmitRegistrationCommand(body.Bsn), ct); return Results.Accepted($"/registrations/{id}", new RegistrationResponse(id.ToString(), RegistrationStatus.Ingediend.ToString(), null)); }); // Read a registration. Its zaak URL appears once the worker has opened the zaak (eventually). app.MapGet("/registrations/{id}", async (string id, IRegistrationStore store, CancellationToken ct) => { if (!Guid.TryParse(id, out var guid)) return Results.NotFound(); var registration = await store.GetAsync(new RegistrationId(guid), ct); return registration is null ? Results.NotFound() : Results.Ok(new RegistrationResponse( registration.Id.ToString(), registration.Status.ToString(), registration.ZaakUrl?.ToString())); }); await app.RunAsync(); public sealed record SubmitRegistrationRequest(string Bsn); public sealed record RegistrationResponse(string RegistrationId, string Status, string? ZaakUrl); public partial class Program;