Skip to content

Component: Smrt.Notifications

Canonical source: SmrtApps/src/Smrt.Notifications/README.md (mirrored below)


Smrt.Notifications

Public surface / entry points

  • Notification record
  • INotificationService
  • NotificationService

Dependencies and integrations

  • Dependency-free notification bus used by UI hosts and background components.

Configuration and operational data

  • No persistent config/state is owned by this library.

Observability and diagnostics

  • Callers should log notification intent/actions via SmrtHub.Logging when troubleshooting.
  • Do not log payload verbatim if it contains user text.

Support Bundle

  • Not applicable directly (library); collect host application logs via Support Bundle.

Overview & Responsibilities

  • Provides a lightweight, in-process notification bus that decouples publishers from UI surfaces (HubWindow toasts, tray popups, etc.).
  • Keeps the payload immutable so subscribers can safely project to multiple UX channels.
  • Designed to be dependency free; consumers wire logging and configuration using the shared SmrtHub.Logging and Smrt.Config building blocks when needed.

Key APIs

  • Notification record — immutable payload with required Title, severity NotificationLevel, optional Message, IconKey, and When timestamp.
  • INotificationService — interface with NotificationPublished event and Publish method for broadcasting notifications.
  • NotificationService — default implementation that raises the event synchronously on the publishing thread.

Publishing Flow

  1. Consumers construct a Notification (ensure titles are localized prior to publishing).
  2. Call INotificationService.Publish. Implementations may be injected via DI or resolved from the shell bootstrap.
  3. Subscribers (e.g., HubWindow view models) handle NotificationPublished to present the message or enqueue it for batched display.
  4. Callers should log notification intent/actions via SmrtHub.Logging when troubleshooting, but never log the payload verbatim if it contains user text.

Threading & Reliability Notes

  • NotificationService raises events synchronously; callers should consider offloading long-running UI work onto dispatcher contexts.
  • Subscribers must handle exceptions internally. Throwing from an event handler will bubble to the publisher.
  • For background components, wrap Publish with retry/backoff logic when the consumer channel can momentarily reject updates.

Testing & Validation

  • Unit-test publishers by substituting INotificationService with a test double and asserting the published payload.
  • For UI subscribers, validate that notifications published during automated flows render correctly and honor severity styling.
  • Contract tests should ensure the DI container wires a single shared instance when using the default implementation.

Directory Map

  • Notification.cs — immutable record defining the payload.
  • NotificationService.cs — default implementation raising events.
  • INotificationService.cs & NotificationLevel.cs — contract and severity enum.
  • Smrt.Notifications.csproj — class library project (net8.0, RID win-x64).