Architecture Decision Record
ADR-071: Device Capability Pattern for Barcode Scanning and QR Display
Status
Accepted (2026-08-12). Amended 2026-08-13: the composition-time string trade-off below was resolved
in v1.147.0 by a deferred-resolution overload; see the updated trade-off entry. Amended 2026-08-14:
source citations re-anchored, and the registration path corrected. Revised 2026-08-31: the
backward-compatible UseCommonBarcodeScanner(string, string) overload and the paired
MauiBarcodeScannerService(string, string) constructor were removed in the v1.173.0
collapse-dual-paths wave, so the deferred-resolution delegates are now the only registration path;
citations re-anchored and the ZXing pin updated. Revised 2026-10-21: the QRCoder pin is 1.8.1
(bumped in v1.249.0), and the package and check-in page anchors are refreshed. Revised 2026-10-26:
anchors refreshed after Directory.Packages.props and CheckInScan.razor moved; versions and
behavior unchanged. Revised 2026-10-28: anchors refreshed for QrErrorCorrectionLevel,
IBarcodeScannerService and NullBarcodeScannerService; behavior unchanged. Revised 2026-11-23:
the framework now requests the camera permission itself through a third contract member,
EnsureCameraAccessAsync, reversing the head-owned permission sub-decision; the QRCoder pin is
1.9.0, and the scanner and package anchors are refreshed.
Context
ADC's badge check-in feature (ADR-072) needs two things that look like one thing: an attendee's device has to show a QR code, and an organizer's device has to read one. They are not the same kind of capability. Rendering a QR is pure managed computation that every head can do, including WebAssembly. Reading one needs a camera, a permission grant, a preview surface and a decode loop, none of which exist on a browser head that this workspace targets.
ADR-042 already decided the shape for the second half: one
small interface per capability in MMCA.Common.UI, a safe fallback TryAdd-registered by
AddDeviceCapabilityDefaults, and a native override registered by the MAUI head after AddUIShared.
It did not decide anything about the first half, and it left two questions open that this feature is
the first to hit. Scanning is the first capability whose null fallback is not decoration: a head
without a camera cannot simply hide the affordance, because the underlying task (check an attendee in)
still has to be completable. And a camera is the first capability whose mere availability costs
something outside the code, since Android CAMERA and iOS NSCameraUsageDescription are declarations
an app store reviewer reads.
Two constraints bound the implementation. MMCA.Common.UI is a single-target net10.0 Razor class
library that must stay WebAssembly-compatible, so a QR generator that reaches for System.Drawing or a
native imaging asset is not available to it. And the pair is not conference-specific: a loyalty or
ticket-redemption flow in MMCA.Store would want the identical two halves, so building them inside ADC
would be the app-local duplication ADR-042 exists to prevent.
Decision
Split the feature by what it actually depends on: QR display ships as a shared component, barcode scanning ships as an ADR-042 capability whose native half is opt-in per head.
- Display is a component, not a capability.
QrCodeImage(MMCA.Common/Source/Presentation/MMCA.Common.UI/Components/Sharing/QrCodeImage.razor) renders a payload as an inline base64 PNG data URI through QRCoder's managedPngByteQRCodepath (:74-77), so it works identically on SSR, Server, WASM and MAUI with no per-head registration at all.Payload(:18-20) andAltText(:26-28) are both[EditorRequired], which is what keeps a generated image from shipping without an accessible name;PixelsPerModule(default 10, clamped to at least 1 at:77),ErrorCorrectionandClasscover sizing and styling. A blank payload renders nothing rather than a broken image (:69-72), and the bitmap is memoized against the three inputs that affect it (:45-59), so a parent re-render does not re-encode.QrCodeButton(Components/Sharing/QrCodeButton.razor) sits beside it: an icon button (:10-14) that opens a dialog (:16-40) showing a public page URL as a code by renderingQrCodeImage(:28-31), forwardingPixelsPerModuleandErrorCorrection(:55-65, defaultQuartile). - The error-correction level is a framework enum, not the generator's.
QrErrorCorrectionLevel(Components/Sharing/QrErrorCorrectionLevel.cs:9-22:Low,Medium(default),Quartile,High) is mapped onto QRCoder'sECCLevelinside the component (QrCodeImage.razor:80-86), so the package's public surface does not pin consumers to the generator that happens to back it today. - Scanning is one contract on the ADR-042 pattern.
IBarcodeScannerService(Services/Capabilities/Media/IBarcodeScannerService.cs:12-29) is three members:bool IsSupported(:15),Task<bool> EnsureCameraAccessAsync(CancellationToken cancellationToken = default)(:22) andTask<string?> ScanAsync(CancellationToken cancellationToken = default)(:28). The contract is that an implementation never throws: an unsupported head, a denied permission, a user-cancelled scan and a cancelled token all returnnullfromScanAsync(:3-11), and the decoded payload is documented as untrusted input (:10).EnsureCameraAccessAsyncreturnsfalsewhen access is denied or unavailable, so a caller can explain why scanning did not start, which anullcannot (:17-21).NullBarcodeScannerService(Services/Capabilities/Media/NullBarcodeScannerService.cs:9-21) reportsIsSupported == false(:12), returnsfalsefromEnsureCameraAccessAsync(:15-16) andnullfromScanAsync(:19-20), TryAdd-registered byAddDeviceCapabilityDefaults(Services/Capabilities/DependencyInjection.cs:38,TryAddSingletonat:79). - The native implementation is opt-in and deliberately NOT folded into
UseMauiDeviceCapabilities. A head asks for the camera by name:UseCommonBarcodeScanner(Func<string> cancelText, Func<string> cameraDescription)onMauiAppBuilder(MMCA.Common.UI.Maui/HostingDependencyInjection.cs:104-115) is the one registration path; it is where ZXing'sUseBarcodeReader()(:111) runs and whereMauiBarcodeScannerServiceis plain-AddSingletoned over the TryAdd default (:112-113). Both delegates are resolved per scan rather than captured at composition, so the scan surface follows the in-app language (:88-95).UseMauiDeviceCapabilities(:30-43) does not call it, and the reason sits on the opt-in method's own doc comment (:86-87): a head that never scans should ship neither the camera handler nor a camera permission declaration. - The scan is a modal page with exactly one resolution.
MauiBarcodeScannerService(Capabilities/Media/MauiBarcodeScannerService.cs:24) marshals to the main thread (:87-89), then insideScanOnMainThreadAsync(:111-136) pushes aBarcodeScanPagemodally (:126) and pops it in afinally(:132-135). The page holds aTaskCompletionSource<string?>(Capabilities/Media/BarcodeScanPage.cs:23-24) that four paths can complete and only the first wins: a decode, the cancel button, the hardware back gesture, andOnDisappearing; the caller'sCancellationTokenis bridged to the sameCancel()(MauiBarcodeScannerService.cs:129). Only 2D formats are read (BarcodeScanPage.cs:36), because the affordance is a QR/DataMatrix scan and admitting the 1D formats multiplies false positives on a shaky handheld frame (:34-35). - The head declares the permission; the framework requests it. The head still declares the
platform permission (Android
CAMERA, iOSNSCameraUsageDescription;HostingDependencyInjection.cs:97-98).MauiBarcodeScannerService.ScanAsyncfirst callsEnsureCameraAccessAsyncand returnsnullwhen it isfalse(MauiBarcodeScannerService.cs:78-81), so no page opens on a camera view that would stay black (:8-11).EnsureCameraAccessAsync(:56-73) marshals the request to the main thread (:65) and treats the throw from a head that never declared the permission asfalse(:67-72); the request itself isPermissions.CheckStatusAsync<Permissions.Camera>followed, when not granted, byPermissions.RequestAsync<Permissions.Camera>(:99-109). A denial and an undeclared permission therefore both read asnullwith no page shown, while a caller that wants to say why scanning did not start callsEnsureCameraAccessAsyncfirst, as ADC's check-in page does (CheckInScan.razor.cs:210). - Supported means Android or iOS.
IsSupportedgates onDeviceInfo.Current.Platform(:51-53); Windows and Mac Catalyst heads keep the null behavior even after opting in.
Packaging follows ADR-042 exactly: QRCoder 1.9.0 is a MMCA.Common.UI dependency and
ZXing.Net.Maui.Controls 0.10.4 (MIT) a MMCA.Common.UI.Maui one, both pinned in
MMCA.Common/Directory.Packages.props (:324, :361), and the MAUI package keeps its
windows-job build and pack.
Rationale
- Rendering a QR is not a device concern, so making it one would have been ceremony. As a capability it would have needed an interface, a null fallback and a native override for something four heads all do the same way, and the null fallback would have meant a head that renders no badge at all. As a component it is one tag with no registration, which is why the web fallback in ADC's check-in flow costs nothing.
- Managed-only is a hard requirement, not a preference. QRCoder's
PngByteQRCodepath needs no native imaging asset, which is what lets the component ride into the WebAssembly head thatMMCA.Common.UImust keep supporting. nullbeats an exception when cancellation is the normal case. A scan is a user-cancellable operation: the attendee walks away, the organizer taps back, the code never decodes. Modelling those as exceptions would make the ordinary path expensive and force every caller into atry. The contract of ADR-042's fallbacks (never throw, report capability throughIsSupported) already said this, and scanning is where it pays.- Opting in by name keeps a permission declaration honest. Folding the camera into
UseMauiDeviceCapabilitieswould have handed every MAUI head an app-store-visible camera permission for a feature it may not have. The one extra line in a head'sMauiProgramis the whole price of that. - Common, not ADC, because nothing here is about conferences. ADR-042 established that reusable infrastructure belongs to the framework and app-specific behavior stays in the app. A QR display component and a barcode reader are the former by construction: ADC's check-in feature supplies only the payload format and the verification, both of which stay in ADC (ADR-072).
- ZXing.Net.MAUI is MIT and is the maintained option. Licensing is a decided axis in this workspace (ADR-016 pins MassTransit to v8 precisely because v9 is commercial), and a permissive license on a package that ships inside a published framework package is not negotiable. The alternative, hand-writing a camera preview and decoder per platform, is a large amount of code to own for a feature measured in one screen.
Trade-offs
- The scan page's text is the caller's delegate, not a string (resolved in v1.147.0).
cancelTextandcameraDescriptionarrive asFunc<string>and are invoked once per scan, when the modal page is built (Capabilities/Media/MauiBarcodeScannerService.cs:85-88), so a head that switches culture at runtime under ADR-027 gets the cancel button, page title and semantic description in the language that is current at the scan rather than the one that was current at startup. The price is on the caller: a head passes the resource lookups themselves (() => localizer["Cancel"]) and has to keep them cheap and side-effect free, because they run on the main thread inside the scan path. QrCodeImagehas no error surface. There is notry/catcharound the encode, so a payload too large for the chosen version and error-correction combination propagates out ofOnParametersSetrather than degrading to a message. The intended payloads are short opaque tokens, so the failure mode is a programming error rather than a data condition, but the component does not say so at runtime.- A null fallback still masks a missing registration. This is ADR-042's recorded trade-off, and here
it is functional rather than decorative: a MAUI head that forgets
UseCommonBarcodeScannergets the same behavior as a browser head. The mitigation is on the consumer, which is why ADC's check-in page shows its scan card only whenIsSupportedis true (CheckInScan.razor:78-102,ScannerAvailableatCheckInScan.razor.cs:46) and always renders a manual attendee search beside it on every head (CheckInScan.razor:122-127, ADR-072), so the task stays completable when the scanner is absent. - Opt-in means the platform matrix is not uniform. A Windows or Mac Catalyst MAUI head that calls
UseCommonBarcodeScannerstill reportsIsSupported == false, so "registered" and "usable" are two different questions a caller has to ask separately. - A generator dependency now ships to the browser.
QRCoderis aMMCA.Common.UIdependency, so it rides down to every WebAssembly client whether or not that client ever renders a code. It is a small managed assembly and trimming applies, but the cost is not zero and it is paid by heads that do not use the feature. - The decoded payload is input, and the contract can only say so. Nothing in the framework validates what a camera decodes. The security of a scan therefore lives entirely in the consumer's verification step, which is exactly why ADR-072's credential is server-verified rather than self-describing.
Revision (2026-10-01)
No decision or rationale changed. The package pin citations are re-anchored to
MMCA.Common/Directory.Packages.props:191 (QRCoder 1.8.0) and :225 (ZXing.Net.Maui.Controls 0.10.4).
The 2D-only reason now quotes the source comment (BarcodeScanPage.cs:34-35: the affordance is a
QR/DataMatrix scan, and 1D formats multiply false positives on a shaky handheld frame). The
null-fallback trade-off is corrected to describe what ADC's check-in page does: it hides the scan card
behind ScannerAvailable => Scanner.IsSupported (CheckInScan.razor:69-93,
CheckInScan.razor.cs:41) and renders the manual search on every head (CheckInScan.razor:113-118),
rather than substituting the manual path for the scanner.
Revision (2026-10-06)
No decision, rationale or behavior changed; versions are unchanged (QRCoder 1.8.0, ZXing.Net.Maui.Controls 0.10.4).
- The package pins recorded in the 2026-10-01 revision now sit at
MMCA.Common/Directory.Packages.props:187(QRCoder) and:221(ZXing.Net.Maui.Controls), andScannerAvailable => Scanner.IsSupportedatCheckInScan.razor.cs:46. - Anchors in the live sections were re-verified against current source and re-anchored
(
QrCodeImage.razor,Directory.Packages.props,CheckInScan.razor.cs).
Revision (2026-10-21)
Re-verified against current source. No decision, rationale or behavior changed; the QRCoder version moved and the package and check-in page anchors drifted.
- The Packaging paragraph now records
QRCoder1.8.1 (MMCA.Common/Directory.Packages.props:194), bumped from 1.8.0 in v1.249.0. It is still a managed, MIT-licensedMMCA.Common.UIdependency, so the WebAssembly reasoning is unchanged. - Anchors re-verified against current source:
Directory.Packages.props:194(QRCoder 1.8.1) and:228(ZXing.Net.Maui.Controls 0.10.4, version unchanged);CheckInScan.razor:76-100(the@if (ScannerAvailable)scan card) andCheckInScan.razor:120-125(the always-rendered manual fallback ending inAttendeeSearchPanel);CheckInScan.razor.cs:46(ScannerAvailable, unmoved).
Revision (2026-10-26)
Re-verified against current source. No decision, rationale or behavior changed, and both versions are unchanged (QRCoder 1.8.1, ZXing.Net.Maui.Controls 0.10.4); only the package and check-in page anchors drifted.
- Anchors re-verified against current source:
MMCA.Common/Directory.Packages.props:250(QRCoder 1.8.1) and:284(ZXing.Net.Maui.Controls 0.10.4);CheckInScan.razor:78-102(the@if (ScannerAvailable)scan card) andCheckInScan.razor:122-127(the always-rendered manual fallback, outside any@if, ending inAttendeeSearchPanelat:127);CheckInScan.razor.cs:46(ScannerAvailable => Scanner.IsSupported, unmoved).
Revision (2026-10-28)
Re-verified against current source. No decision, rationale or behavior changed; the enum values, the two-member scanner contract and the null fallback are as recorded, and only their citations drifted.
- Anchors re-verified against current source:
Components/Sharing/QrErrorCorrectionLevel.cs:9-22(Low:12,Medium:15,Quartile:18,High:21;Mediumis the default set atQrCodeImage.razor:39);Services/Capabilities/Media/IBarcodeScannerService.cs:12-22(IsSupported:15,ScanAsync:21, never-throws contract in the doc comment at:3-11, the untrusted-payload note at:10);Services/Capabilities/Media/NullBarcodeScannerService.cs:9-17(IsSupported => falseat:12, thenullresult at:15-16).
Revision (2026-11-23)
Re-verified against current source. The headline split (QR display as a shared component, scanning as an opt-in ADR-042 capability), the never-throws contract, the modal page and the 2D-only formats are unchanged; the permission sub-decision is reversed and the scanner contract grew a member.
- The Decision bullet "Permission stays with the head, not the framework" is replaced. The framework
now requests the camera permission:
MauiBarcodeScannerService.ScanAsynccallsEnsureCameraAccessAsyncand returnsnullonfalse(MauiBarcodeScannerService.cs:78-81), andRequestCameraAsynccallsPermissions.CheckStatusAsync<Permissions.Camera>thenPermissions.RequestAsync<Permissions.Camera>(:99-109) on the main thread (:65), treating the throw from an undeclared permission asfalse(:67-72). A denial now returnsnullwith no page shown instead of a preview that never decodes (:8-11). The head still declares the platform permission (HostingDependencyInjection.cs:97-98). ADC's check-in page calls the new member before it scans (CheckInScan.razor.cs:210). IBarcodeScannerServiceis three members, not two:EnsureCameraAccessAsync(:22) joinsIsSupported(:15) andScanAsync(:28), andNullBarcodeScannerServicereturnsfalsefrom it (NullBarcodeScannerService.cs:15-16).- The Packaging paragraph records
QRCoder1.9.0 (MMCA.Common/Directory.Packages.props:324), moved from 1.8.1. Its license is not restated, because the 1.9.0 license is not checked here. - The display bullet now names
QrCodeButton(Components/Sharing/QrCodeButton.razor:28-31), the shared icon button whose dialog rendersQrCodeImagefor a public page URL. - Anchors re-verified against current source:
IBarcodeScannerService.cs:12-29(doc comment:3-11, untrusted-payload note:10);NullBarcodeScannerService.cs:9-21(:12,:15-16,:19-20);Services/Capabilities/DependencyInjection.cs:79(TryAddSingleton, insideAddDeviceCapabilityDefaultsat:38);MauiBarcodeScannerService.cs:24(class, unmoved),:51-53(IsSupported, unmoved),:85-88(per-scan delegate invocation),:87-89(main-thread marshal),:111-136(ScanOnMainThreadAsync),:126(PushModalAsync),:129(token bridged toCancel),:132-135(PopModalAsyncinfinally);Directory.Packages.props:361(ZXing.Net.Maui.Controls 0.10.4, version unchanged).
Related
ADR-042 (the capability pattern this extends: contract in
MMCA.Common.UI, native implementation in MMCA.Common.UI.Maui, override after AddUIShared),
ADR-072 (the ADC feature that motivated both halves and owns the
payload format and its verification), ADR-027 (the culture model the
per-scan text delegates follow), ADR-016
(lockstep release and the licensing posture behind the ZXing choice),
ADR-045 (the previous capability addition, and the same
treatment of untrusted device input).