Register typed command handlers, dispatch commands against a context, and read back what matched.
A Container with a RegisterCommandDispatcher<Session> and several handlers
(SquidStd.Services.Core), dispatching commands that carry a Session context. One command type
has two handlers - both run on dispatch.
- .NET 10 SDK
dotnet add package SquidStd.Services.Core
Register the dispatcher for the context type, then each handler. EchoCommand has two handlers
(EchoHandler and AuditHandler); both will run. The subscription loop is what
CommandDispatcherActivator<Session> does at runtime - inlined here to keep the sample
self-contained.
The context (here a Session) is passed explicitly at dispatch time - in a server this is the
session the message arrived on.
DispatchAsync returns a result reporting whether any handler matched and how many ran. Nothing
is registered for UnknownCommand, so Matched is false and HandlerCount is 0.
dotnet run --project samples/SquidStd.Samples.Commands