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. Eight channels: SMS, email, web, push, in-app, WhatsApp, and webhook.

You'll learn
  • Provision NotificationHub into 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

bash
kanject baas deploy notifications --env dev

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.Region    = appSettings.AwsRegion;    options.Namespace = 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 priorityNotificationDispatchPriority routes transactional sends through a high-priority queue ahead of bulk.

What you get

  • Eight channelsPublishChannel: 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 — implement IHubDispatchProvider and mark it [NotificationPublisherProvider] to add a channel/provider.
Recap
  • Provision with kanject baas deploy notifications, register with AddNotificationHubServer(options => …).
  • Send via IHubIngestionManagerIngestContentNotificationAsync (one channel) or IngestEventNotificationAsync (topic + payload).
  • PublishChannel is single-select (8 channels), not a flags bitmask; scheduling/cancellation ride event notifications.
  • Add delivery providers by implementing IHubDispatchProvider + [NotificationPublisherProvider].
Was this page helpful?