SubmitRegistration creates the aggregate, persists it, starts the registratie process via the Workflow Client, records the instance id and upserts. OpenZaakWorker loads the correlated registration, opens a zaak via the ACL, attaches it and saves; an unknown registration throws (job redelivered), and an already-opened zaak short- circuits without opening a second one (§8.6). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
34 lines
1.5 KiB
C#
34 lines
1.5 KiB
C#
using Big.Domain;
|
|
|
|
namespace Big.Application;
|
|
|
|
/// <summary>A zorgprofessional's request to register, in domain language. No ZGW concepts.</summary>
|
|
public sealed record SubmitRegistrationCommand(string Bsn);
|
|
|
|
/// <summary>
|
|
/// The submit use case: create the <see cref="Registration"/> aggregate (INGEDIEND), persist it,
|
|
/// then start the registratie workflow process and record its instance id. It returns as soon as
|
|
/// the process is started — opening the zaak happens later, off the request path, in the external-task
|
|
/// worker (ADR-0009). Persisting <em>before</em> starting the process closes the race where the worker
|
|
/// acquires the OpenZaakAanmaken job before the aggregate it correlates to exists.
|
|
/// </summary>
|
|
public sealed class SubmitRegistration(IRegistrationStore store, IWorkflowClient workflow)
|
|
{
|
|
public async Task<RegistrationId> HandleAsync(SubmitRegistrationCommand command, CancellationToken ct = default)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(command);
|
|
|
|
var registration = Registration.Submit(command.Bsn);
|
|
|
|
// Persist before starting the process so the worker can correlate the OpenZaakAanmaken
|
|
// job back to an aggregate that already exists (ADR-0009).
|
|
await store.SaveAsync(registration, ct);
|
|
|
|
var processInstanceId = await workflow.StartRegistrationProcessAsync(registration.Id, ct);
|
|
registration.RecordProcessStarted(processInstanceId);
|
|
await store.SaveAsync(registration, ct);
|
|
|
|
return registration.Id;
|
|
}
|
|
}
|