Přeskočit obsah

Pattern 8: Biometric Enrollment

This pattern is the biometric-specific specialization of Pattern 15: Enrollment Process. Read Pattern 15 first.

Current Handler Shape

Enrollment is implemented as a generated command handler, usually a static method. The command carries EnrollmentId and PersonId; the adapter opens an EnrollmentSession, captures the vendor template and completes the session.

public static class FaceEnrollment
{
    public static async Task<DeviceCommandResult> EnrollFace(
        BiometricTerminal terminal,
        Access.Enroll.Face command,
        Protocol protocol,
        IEnrollmentService enrollment,
        CancellationToken ct)
    {
        // disposing a session that was not completed clears the enrollment status
        await using var session = enrollment.Begin(terminal);

        try
        {
            var scanned = await protocol.ScanFace(ct);

            var data = new EnrollmentData
            {
                EnrollmentId = command.EnrollmentId,
                PersonId = command.PersonId,
                Technology = "vendor.face",
                TemplateData = scanned.Template,
            };

            return await session.Complete(data, ct);
        }
        catch (Exception ex) when (ex is TimeoutException or OperationCanceledException)
        {
            return new DeviceCommandResult(CommandResult.Timeout);
        }
    }
}

Rules

  • Do not store enrollment session state on the Thing unless the protocol requires a long-running device mode that cannot be represented by the command/session.
  • Use command.EnrollmentId and command.PersonId; do not read current session IDs from IEnrollmentService.
  • Hold await using var session = enrollment.Begin(thing) before capture and call session.Complete(data, ct) after successful capture. The session clears the enrollment status on every other path; the handler never writes the enrollment status itself.
  • Return timeout for user cancellation, device timeout, or command cancellation.
  • Document template technology strings and whether templates are vendor-proprietary.

Technology Identifiers

Use vendor-specific technology strings:

  • vendor.fingerprint.v2
  • vendor.face.visible
  • vendor.face.ir
  • vendor.iris

The technology string must identify the template format, not just the biometric modality.