KnockBox.Platform
1.0.0-prerelease
dotnet add package KnockBox.Platform --version 1.0.0-prerelease
NuGet\Install-Package KnockBox.Platform -Version 1.0.0-prerelease
<PackageReference Include="KnockBox.Platform" Version="1.0.0-prerelease" />
<PackageVersion Include="KnockBox.Platform" Version="1.0.0-prerelease" />
<PackageReference Include="KnockBox.Platform" />
paket add KnockBox.Platform --version 1.0.0-prerelease
#r "nuget: KnockBox.Platform, 1.0.0-prerelease"
#:package KnockBox.Platform@1.0.0-prerelease
#addin nuget:?package=KnockBox.Platform&version=1.0.0-prerelease&prerelease
#tool nuget:?package=KnockBox.Platform&version=1.0.0-prerelease&prerelease
KnockBox.Platform
Hosting SDK for KnockBox game plugins.
KnockBox is a Blazor Server host that loads party games as runtime-discovered plugins. This package provides the bootstrap surface a host (dev or production) needs to discover plugins, wire their services into DI, serve their static assets, and render them through the platform's Home / Error / NotFound chrome.
Who references this? Your host project — a local DevHost for development, or a production host binary. Who does NOT reference this? Game plugins. A plugin referencing
KnockBox.Platformbreaks runtimeAssemblyLoadContextisolation and will cause type-identity failures at plugin load. Plugins reference onlyKnockBox.Core.
Minimal host
using KnockBox.Platform;
var builder = WebApplication.CreateBuilder(args);
// Explicit-mode: register each game module directly. Ideal for DevHosts.
builder.AddKnockBoxPlatform(options =>
{
options.PluginDiscovery = PluginDiscoveryMode.Explicit;
options.AddGameModule<MyGameModule>();
// options.AddGameModule<AnotherGameModule>();
});
var app = builder.Build();
app.UseKnockBoxPlatform();
app.Run();
For a production host that loads plugins from a directory:
builder.AddKnockBoxPlatform(options =>
{
options.PluginDiscovery = PluginDiscoveryMode.Directory; // default
options.PluginsPaths.Clear();
options.PluginsPaths.Add("games"); // relative to AppContext.BaseDirectory
options.PluginsPaths.Add("/var/lib/knockbox/games"); // or an absolute path
options.Branding.AppTitle = "My KnockBox Party";
options.Branding.HomeHeroTitle = "My KnockBox Party";
});
Each plugin subfolder under the configured PluginsPaths (games/MyGame/, games/AnotherGame/, …) is loaded into its own AssemblyLoadContext. The loader reflects each assembly for IGameModule implementations, activates them, and calls RegisterServices.
Host override hook: IGameAvailabilityService
The Platform ships a default AllGamesEnabledService that reports every game as enabled. Hosts that want per-game gating (disable cards, admin toggles, etc.) should register their own implementation on the service collection before calling AddKnockBoxPlatform:
builder.Services.AddSingleton<IGameAvailabilityService, MyFileBackedAvailabilityService>();
builder.AddKnockBoxPlatform(options => { ... });
The order matters: AddKnockBoxPlatform uses TryAddSingleton so a pre-existing registration wins. If the default fallback was installed (because the host registered after AddKnockBoxPlatform or forgot to register at all), the Platform logs an Information-level message at startup so misorders are diagnosable.
Plugin discovery modes
| Mode | When to use | Behaviour |
|---|---|---|
PluginDiscoveryMode.Directory (default) |
Production hosts, or any scenario where plugins ship as loose DLL folders. | Scans every path in PluginsPaths for plugin subfolders and loads each into its own ALC. |
PluginDiscoveryMode.Explicit |
Dev hosts, tests, and any scenario with direct ProjectReferences to the plugin. |
Uses modules registered via options.AddGameModule<T>(). No directory scan, no ALC isolation. The caller must set this mode explicitly; AddKnockBoxPlatform throws if you leave it on Directory with explicit modules registered. |
Configuration options
| Option | Purpose |
|---|---|
Branding.AppTitle |
Header title shown once a game session is active. |
Branding.HomeHeroTitle |
Large hero title on the home page. |
Branding.HomePageTitle |
Browser tab / <title> on the home page. |
PluginDiscovery |
Directory (default) or Explicit. |
PluginsPaths |
Ordered list of relative or absolute paths to plugin folder roots. Default: single entry "games". |
Extension points
AddKnockBoxPlatform(configure)— registers all platform services, performs plugin discovery, configures Razor components.UseKnockBoxPlatform()— convenience wrapper aroundUseKnockBoxPlatformMiddleware()+MapKnockBoxPlatformEndpoints(). Good for dev hosts with no host-specific middleware.UseKnockBoxPlatformMiddleware()— Serilog request logging, exception handler, HSTS, status-code pages, HTTPS redirect, anti-forgery. Call this before any host-specific middleware (auth, rate limiting, admin port filtering).MapKnockBoxPlatformEndpoints()/MapKnockBoxPlatformEndpoints<TRootComponent>()— maps static assets, per-plugin/_content/{PluginName}mounts, and Blazor endpoints. Use the generic overload if your host supplies its ownApp.razor.IGameAvailabilityService— override with a host-supplied implementation (e.g., file-backed or admin-toggled) to gate individual games. The platform registers a default "all enabled" fallback viaTryAddSingleton.
Package contents at a glance
- Bootstrap extensions:
KnockBoxPlatformExtensions,KnockBoxPlatformOptions,KnockBoxPlatformOptionsExtensions. - Platform pages:
Home,Error,NotFound,MainLayout,ReconnectModal(served at/,/error,/not-found). - Lobby management:
LobbyService,LobbyCodeService(6-character profanity-filtered codes). - Session infrastructure:
SessionServiceProvider,SessionTokenProvider,UserService,TickService. - Client storage:
ILocalStorageService,ISessionStorageService(JS-interop browser storage wrappers). - Profanity filter: Aho-Corasick automaton over an embedded English word list; used by
LobbyCodeService.
Developer reference
Full end-to-end walkthrough for building a plugin (from scaffolding through shipping):
https://github.com/jcub1011/KnockBox/blob/main/docs/making-a-game-plugin.md
Related packages
KnockBox.Core— the contract package plugins reference.KnockBox.Templates—dotnet newscaffolding for a plugin + dev host + tests.
License
MIT. See LICENSE.txt in the repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FluentValidation (>= 12.1.1)
- KnockBox.Core (>= 1.0.0-prerelease)
- Serilog (>= 4.3.1)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Sinks.File (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-prerelease | 263 | 4/23/2026 |