KnockBox.Platform 1.0.0-prerelease

This is a prerelease version of KnockBox.Platform.
dotnet add package KnockBox.Platform --version 1.0.0-prerelease
                    
NuGet\Install-Package KnockBox.Platform -Version 1.0.0-prerelease
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KnockBox.Platform" Version="1.0.0-prerelease" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KnockBox.Platform" Version="1.0.0-prerelease" />
                    
Directory.Packages.props
<PackageReference Include="KnockBox.Platform" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KnockBox.Platform --version 1.0.0-prerelease
                    
#r "nuget: KnockBox.Platform, 1.0.0-prerelease"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KnockBox.Platform@1.0.0-prerelease
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KnockBox.Platform&version=1.0.0-prerelease&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=KnockBox.Platform&version=1.0.0-prerelease&prerelease
                    
Install as a Cake Tool

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.Platform breaks runtime AssemblyLoadContext isolation and will cause type-identity failures at plugin load. Plugins reference only KnockBox.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 around UseKnockBoxPlatformMiddleware() + 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 own App.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 via TryAddSingleton.

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

License

MIT. See LICENSE.txt in the repository.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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