Bonoscan.Components.Server 0.33.0

Bonoscan.Components.Server

The Blazor Server scan engine for Bonoscan.Components. A thin JS live loop POSTs camera frames to two off-circuit HTTP endpoints — /_bonoscan/detect (DocAligner ONNX, model embedded in this package) and /_bonoscan/capture (server-side C# warp) — so per-frame detection never touches the SignalR circuit. Only discrete state transitions and the final captured image cross the circuit.

For Blazor WebAssembly / MAUI use Bonoscan.Components.Client.

The DocAligner model is embedded in this package and loaded by default — you host no model.

Install

<!-- nuget.config -->
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="bonoscan-local" value="/absolute/path/to/scanner/local-feed" />
  </packageSources>
</configuration>
<PackageReference Include="Bonoscan.Components.Server" Version="0.30.0" />

Build the feed with ./build-nugets.sh in the scanner repo.

Setup

// Program.cs
builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents()
    .AddHubOptions(o => o.MaximumReceiveMessageSize = 32 * 1024 * 1024);

builder.Services.AddBonoscanServer(o =>
{
    o.Scanner = s =>
    {
        s.GuideAspect   = 0.707;
        s.CaptureWidth  = 2480;
        s.CaptureHeight = 3508;
        s.Mime          = "image/jpeg";
        s.Quality       = 0.92;
    };
});

var app = builder.Build();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapBonoscanDetection();   // maps /_bonoscan/detect and /_bonoscan/capture
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();

Link the stylesheet in App.razor (or _Host):

<link rel="stylesheet" href="_content/Bonoscan.Components/bonoscan.css" />

Then drop <DocumentScanner OnCaptured="..." /> on an interactive-server page (see the Bonoscan.Components README for the component and ScannerResult reference).

Important: raise the SignalR message limit

The captured image is returned to .NET over the SignalR circuit. Blazor's default MaximumReceiveMessageSize is 32 KB — far smaller than a scanned image — so without raising it the circuit drops mid-capture and the result never arrives. The AddHubOptions(...) line above is required.

Secure context

getUserMedia needs HTTPS (or localhost). A LAN IP over plain HTTP will not get camera access; the component fails fast with a clear message.

What this package registers

AddBonoscanServer(...) registers the shared ScannerOptions, the native DocAligner detection service (AddDocAlignerDetection, idempotent — the ~13 MB model loads once however often it is called), and an IScannerEngineFactory the components use to build their own ServerScannerEngine. The engine itself is deliberately not a container-tracked service, so mounting the scanner repeatedly cannot accumulate dead engines on the circuit. MapBonoscanDetection() maps the off-circuit detect/capture endpoints.

Endpoint exposure

/_bonoscan/detect and /_bonoscan/capture are anonymous and carry no antiforgery token (the JS loop POSTs to them directly), and each capture request decodes a full-resolution image and runs an ONNX inference. Request bodies are capped at BonoscanServerOptions.MaxRequestBytes (32 MB by default) and a larger body is rejected with 413 before anything is buffered or decoded. If the endpoints are reachable from outside your app, attach your own policy — the callback runs against both of them:

app.MapBonoscanDetection(configureEndpoints: b => b
    .RequireAuthorization("scan")
    .RequireRateLimiting("scan"));

Licensing

Library code MIT. Dependencies: ONNX Runtime (MIT), StbImageSharp (MIT/public domain). The embedded DocAligner weights are Apache-2.0 (DocsaidLab/DocAligner).

No packages depend on Bonoscan.Components.Server.

.NET 10.0

Version Downloads Last updated
0.34.0 9 11/10/2026
0.33.2 13 11/04/2026
0.33.1 3 11/04/2026
0.33.0 3 11/04/2026
0.31.0 173 06/04/2026