MapBlazor: Architecture of a Blazor Component Library for ArcGIS Maps (Series)

MapBlazor is a Razor Class Library that puts the ArcGIS Maps SDK for JavaScript (Esri) behind a typed .NET API. A Blazor app, whether Server, WebAssembly or Auto, can add 2D maps and 3D scenes, layers, basemaps, drawing, selection, popups and widgets without writing JavaScript. This series covers the architecture behind it: how the JavaScript SDK is bundled and shipped, how the SDK is bootstrapped, how .NET and JS talk to each other, how map state flows back into Blazor, and how it is packaged and tested. Part Topic 01 Goals, project layout and the build pipeline 02 Configuration-first SDK bootstrapping and pluggable authentication (bring your own IdP) 03 The .NET ↔ JavaScript bridge: registry, DTOs, callbacks, disposal 04 The MapView<TMap> component and per-map services 05 Layers, basemaps, 2D/3D, drawing, selection, popups and widgets 06 State with Fluxor, error contracts, packaging and testing Stack: .NET 10 Razor Class Library, ArcGIS Map...

MapBlazor Architecture, Part 1: Goals, Project Layout and the Build Pipeline

Goals

  1. No JavaScript for consumers. Everything a page needs is a component parameter or an injected service.
  2. Many maps per page. Each map is identified by a type, so services and state never mix maps up.
  3. The SDK stays the source of truth. Live ArcGIS objects never cross into .NET. .NET sends intentions and receives summaries.
  4. Works in every render mode. Server, WebAssembly and Auto all share one code path.
  5. Ships as one NuGet package, including the SDK's own assets.

Solution layout

MapBlazor (Razor Class Library)IJSRuntimeesbuildcallbacksIState / SubscribeToActionComponentsMapView<TMap>Servicesper-map, generic overTMapStoreFluxor state, actions,effectsJsInteropDTOs, mappers, callbackmodulesScripts/*.tsfacade + feature moduleswwwrootbundled js + ArcGIS assetsBlazor app
Folder Holds
Components/ MapView<TMap>, the only Razor component
Services/ Layer, basemap, extent, zoom, draw, selection, highlight and popup services
Store/ Fluxor features: map view state (keyed by map type) and layer state
JsInterop/Data Internal DTO records with explicit JSON names
JsInterop/Modules DotNetObjectReference callback receivers
Data/ The public model: geometry, layer descriptions, symbols, renderers
Scripts/ TypeScript: bootstrap, map builder, layers, draw, select, widgets
wwwroot/ Build output, served as static web assets at _content/MapBlazor/...

The JavaScript build

The TypeScript side is a normal npm project inside the RCL:

{
  "type": "module",
  "dependencies": {
    "@arcgis/core": "^5.0.0",
    "@arcgis/map-components": "^5.0.0",
    "@esri/calcite-components": "^5.0.0"
  },
  "devDependencies": { "esbuild": "^0.25.0", "typescript": "^5.9.0" }
}

esbuild bundles two entry points:

Entry Role
core/bootstrap.ts Tiny, with no SDK imports. It receives configuration, seeds esriConfig, then loads everything else (Part 2)
mapBlazor.ts The facade: re-exports every feature function (Part 3)
// esbuild.config.js
await esbuild.build({
  entryPoints: ["Scripts/mapBlazor.ts", "Scripts/core/bootstrap.ts"],
  bundle: true, format: "esm", splitting: true, target: "es2020",
  outdir: "wwwroot/js", sourcemap: true, minify: isRelease,
});

Code splitting matters: the SDK is large, and features are only loaded when first used.

SDK assets (workers, fonts, localization files, Calcite icons) are copied from node_modules into wwwroot/assets. The SDK is then pointed at them with assetsPath. Write a small version stamp next to them, so the copy step runs only when the SDK version changes.

Wiring npm into MSBuild

<Target Name="BuildScripts" BeforeTargets="PreBuildEvent" Condition="'$(SkipScriptBuild)' != 'true'">
  <Exec Command="npm ci" Condition="!Exists('node_modules/.package-lock.json')" />
  <Exec Command="node esbuild.config.js $(ScriptBuildArgs)" />
</Target>
  • Call node directly and rely on exit codes. Searching the output for the word "Error" is fragile.
  • Provide an opt-out property (SkipScriptBuild) for CI legs that build the JS separately.
  • Git-ignore the generated wwwroot/js and wwwroot/assets. The package build produces them.

Versioning

Encode both versions in the package version: 1.4.0-sdk5.0.18 means library 1.4.0 built against SDK 5.0.18. Consumers can then see which SDK they're getting, and upgrading the SDK is a visible version bump.

Keep the README, the package description and the actual package-lock.json in step. Generate the description from the lock file in CI if you can.

Comments

Popular posts from this blog

My Cloud Notes

My CSharp Notes