Kanject.NotificationHub

View .md

A multi-channel notification engine — send a ready-made message on a single channel, or publish an event and let the hub resolve templates, channels, scheduling, and cancellation. Seven channels: SMS, email, web, push, in-app, WhatsApp, and webhook.

You'll learn
  • Let NotificationHub create its tables and queues in your AWS account
  • Register it with AddNotificationHubServer and inject IHubIngestionManager
  • Send a content notification and publish an event notification
  • Understand the channel model, dispatch priority, and bring-your-own providers

Provision

NotificationHub creates its own DynamoDB tables, indexes, and SQS queues in your account when Setup is true on its options; leave it false (the default) when those resources already exist.

Register it in your service

Register with AddNotificationHubServer(options => …) from Kanject.NotificationHub.Provider.AwsV2.Extensions, passing a typed AwsHubConfiguration delegate (region, namespace, credentials). A generic AddNotificationHubServer<THubDbContext> overload lets you supply your own data context.

csharp
using Kanject.NotificationHub.Provider.AwsV2.Extensions;​var builder = WebApplication.CreateBuilder(args);​builder.Services.AddNotificationHubServer(options =>{    options.AwsRegionEndpoint = appSettings.AwsRegion;    options.TableNamespace    = appSettings.Stage;   // per-stage isolation});​var app = builder.Build();app.Run();

Send a notification

Inject IHubIngestionManager. There are two entry points: IngestContentNotificationAsync sends a message you've already rendered on one PublishChannel; IngestEventNotificationAsync publishes an event topic + payload and lets the hub resolve templates, channels, and any scheduling on its side.

csharp
// Inject IHubIngestionManager — the send surface has two entry points.public class OrderNotifier(IHubIngestionManager hub){    // Content notification: you supply the rendered message + one channel.    public Task ShippedAsync(string toEmail) =>        hub.IngestContentNotificationAsync(new IngestContentNotificationRequest        {            To             = toEmail,            Subject        = "Your order shipped",            Body           = "It's on the way — arriving tomorrow.",            Channel        = PublishChannel.Email,            DispatchPriority = NotificationDispatchPriority.Transactional,        });​    // Event notification: publish an event topic + payload; templates and    // channels resolve on the hub side (including scheduling/cancellation).    public Task OrderPlacedAsync(JsonDocument payload) =>        hub.IngestEventNotificationAsync(new IngestNotificationRequest        {            EventTopic = "order.placed",            Payload    = payload,        });}

Scheduling & cancellation

  • Delayed / recurring / calendar — scheduled sends via NotificationScheduleType (Delayed, Recurring, Calendar).
  • Smart cancellation — a ScheduleCancellationEventDto { EventTopic, CorrelationId } drops a queued send when a correlated event arrives.
  • Dispatch priority — NotificationDispatchPriority routes transactional sends through a high-priority queue ahead of bulk.

What you get

  • Seven channels — PublishChannel: SMS, Email, Web, Push, InApp, WhatsApp, Webhook (single-select per content send).
  • Two send modes — pre-rendered content sends, or event notifications the hub templates and routes.
  • Scheduling — delayed, recurring, and calendar sends, with correlated-event cancellation.
  • Dispatch priority — separate high- and low-priority outgoing queues.
  • Bring your own delivery — the SDK ships no delivery provider. Implement IHubDispatchProvider for each account you send through and register it with RegisterDispatchProvider<T>(key).
Recap
  • Register with AddNotificationHubServer(options => …); set Setup = true to have it create its tables and queues.
  • Send via IHubIngestionManager — IngestContentNotificationAsync (one channel) or IngestEventNotificationAsync (topic + payload).
  • PublishChannel is single-select (7 channels), not a flags bitmask; scheduling/cancellation ride event notifications.
  • Add delivery providers by implementing IHubDispatchProvider + [NotificationPublisherProvider].
Was this page helpful?