Kanject.Core.Realtime.Abstractions 1.3.0

Prefix Reserved
dotnet add package Kanject.Core.Realtime.Abstractions --version 1.3.0
                    
NuGet\Install-Package Kanject.Core.Realtime.Abstractions -Version 1.3.0
                    
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="Kanject.Core.Realtime.Abstractions" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kanject.Core.Realtime.Abstractions" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Kanject.Core.Realtime.Abstractions" />
                    
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 Kanject.Core.Realtime.Abstractions --version 1.3.0
                    
#r "nuget: Kanject.Core.Realtime.Abstractions, 1.3.0"
                    
#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 Kanject.Core.Realtime.Abstractions@1.3.0
                    
#: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=Kanject.Core.Realtime.Abstractions&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Kanject.Core.Realtime.Abstractions&version=1.3.0
                    
Install as a Cake Tool

Kanject.Core.Realtime.Abstractions

The transport-neutral contract for pushing messages to connected clients (Core proposal 0058). A product publishes to an audience, which is a user, several users or a topic, through IRealtimePublisher. The host decides whether the message travels in process, over API Gateway WebSockets or over AppSync Events. The package depends only on the BCL.

Installation

dotnet add package Kanject.Core.Realtime.Abstractions

Targets .NET 9, .NET 10 and .NET 11. Add Kanject.Core.Realtime for AddRealtime() and the in-process transport.

Quick start

public sealed class ConversationBroadcaster(IRealtimePublisher realtime)
{
    public Task<RealtimePublishResult> MessageAddedAsync(Conversation conversation, MessageAdded added, CancellationToken ct) =>
        realtime.PublishAsync(
            conversation.IsLargeRoom
                ? RealtimeAudience.Topic("Conversations", conversation.Id)
                : RealtimeAudience.Users(conversation.ParticipantIds),
            type: "message_added", added, ChatJsonContext.Default.MessageAdded, requestId: added.RequestId, ct);
}

The product says who a caller is and what they may listen to, once, for every transport:

public sealed class ChatRealtimeAuthorizer(ITokenValidator tokens, IConversationReader conversations) : IRealtimeAuthorizer
{
    public async ValueTask<RealtimePrincipal?> AuthenticateAsync(RealtimeConnectRequest request, CancellationToken ct) =>
        await tokens.ValidateAsync(request.Token, ct) is { IsValid: true } token
            ? new RealtimePrincipal(token.UserId, token.ExpiresAt)
            : null;

    public ValueTask<bool> CanSubscribeAsync(RealtimePrincipal principal, RealtimeTopic topic, CancellationToken ct) =>
        topic.Kind == "Conversations" ? conversations.IsParticipantAsync(topic.Id, principal.UserId, ct) : ValueTask.FromResult(false);
}

The envelope

Every transport delivers the same JSON, so one client parser serves all of them:

{ "type": "message_added", "id": "0193a4c6-…", "requestId": "0193a4c5-…", "sentAt": "2026-11-23T10:15:00.0000000Z", "data": { … } }
  • id is Core's, a new version-7 Guid for each publish. A client drops an id it has already seen.
  • requestId is the one the sending client minted, so that client can drop its own echo. It is left out when there is none.
  • data goes through your JsonTypeInfo<T>; Core never reflects. RealtimeEnvelopeJson writes and reads the envelope.

Rules every transport applies

  • A topic's kind is a PascalCase plural noun of 1–50 letters and digits, such as Conversations. Users is reserved in any casing (KANRT001).
  • A message type is 1–64 lower-case letters, digits, _, . or -, starting with a letter, such as message_added (KANRT005).
  • The payload ceiling is 32 KB, the whole envelope, one API Gateway frame. An envelope over it is refused before anything is sent (KANRT003). A host may raise it to its transport's own limit.
  • Core's four subscription rules come before your authorizer (RealtimeSubscriptionRules). A principal subscribes to its own user channel and no one else's. A wildcard is always refused. A principal stays inside its own tenant, taken from the principal and never from the request. Nothing is delivered after the principal expires, where the transport can end a connection.

The first two are checked when the call runs. Add Kanject.Core.Realtime.Annotations to have a constant checked at build instead: [TopicKindName] and [MessageTypeName] mark the parameters that take one, on RealtimeTopic.Create, RealtimeAudience.Topic, IRealtimePublisher.PublishAsync, RealtimeInboundContext.ReplyAsync and RealtimeEnvelopeJson.Create (KANRT250–KANRT252). Put the same marker on your own wrapper's string parameter and its callers are checked too.

Declarations and frames

The declaration attributes live here, so a product declares its realtime catalogue in the assembly that holds its payloads; Kanject.Core.Realtime.Annotations reads them and generates the code (Core proposal 0067):

Attribute On Gives
[RealtimeMessage("message_added")] A payload type PublishMessageAddedAsync and ReplyMessageAddedAsync
[RealtimeTopicKind("Conversations")] A static partial class Kind, Of, Audience, Is
[RealtimeJsonContext] The assembly's JsonSerializerContext The metadata every payload travels through
[RealtimeFrames], [RealtimeFrame("send_message")] A partial class and its methods A generated IRealtimeInboundHandler
[assembly: RealtimeMessagesClass("ChatMessages")] The assembly The generated class's name

They are [Conditional], so nothing of them reaches your assembly unless KANJECT_REALTIME_DECLARATIONS is defined.

For frames a client sends, {"action": …, "requestId": …, "data": { … }}:

  • RealtimeFrameReader.TryRead reads the action, the request id and the bytes of data in one pass, and TryReadData reads the data through its source-generated metadata. A hand-written handler may use them too.
  • RealtimeInboundContext.RefuseFrameAsync(action, reason) answers the calling connection with Core's realtime.ack, {"action": …, "ok": false, "reason": …}. The reasons are RealtimeFrameRefusals.UnknownAction and InvalidFrame. It is virtual, with a default, so an existing context needs no change.
  • RealtimeReservedFrameActions names the four actions Core handles itself (subscribe, unsubscribe, ping, renew).
  • For libraries and hosts composing frames and subscribe rules in one host (Core proposal 0069): IRealtimeFrameActionClaims declares the actions an IRealtimeInboundHandler claims (static abstract Actions), and IRealtimeTopicAuthorizer + IRealtimeTopicKindClaims (static abstract Kinds) rule on topic subscriptions by topic kind.

Capabilities

The transports differ. API Gateway lists and ends connections; AppSync Events fans out itself but can't end a subscription. Each transport reports a RealtimeCapabilities, and a member it can't serve throws RealtimeCapabilityNotSupportedException naming the capability (KANRT004). Branch on the capabilities, never on a provider's type.

Diagnostics

Code Meaning
KANRT001 A topic kind is malformed or reserved
KANRT002 RealtimeAudience.Users names no user
KANRT003 An envelope is over the payload ceiling
KANRT004 A member needs a capability the transport lacks
KANRT005 A message type is malformed
KANRT006 Text isn't Core's envelope

License

Licensed under the Kanject Code Libraries License Agreement (KCLLA); the full text ships in this package as LICENSE.md. Organizations whose trailing-twelve-month gross revenue and total funding raised are each below US$250,000 may use it at no cost under the Free Tier. At or above either threshold a commercial license is required — contact commercial@kanjectbusiness.com.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Kanject.Core.Realtime.Abstractions:

Package Downloads
Kanject.Core.Realtime

Kanject Core realtime — AddRealtime() and the in-process default transport for Kanject.Core.Realtime.Abstractions (proposal 0058): connections, subscriptions and delivery held in memory, with Core's subscription rules, the product's IRealtimeAuthorizer, the connection observer, inbound frames and every D10 control. For tests and local runs; providers for API Gateway WebSockets and AppSync Events plug into the same builder.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 7 11/26/2026
1.2.0 57 11/26/2026
1.1.0 62 11/26/2026
1.0.0 67 11/24/2026

- Adds IRealtimeFrameActionClaims, IRealtimeTopicAuthorizer, IRealtimeTopicKindClaims, RealtimeReservedFrameActions, and KANRT055-057 (proposal 0069)