Skip to content

Configuration ​

All GrydNotifications settings are configured through GrydNotificationsOptions:

csharp
builder.Services.AddGrydNotifications(options =>
{
    // ... configuration here
});

GrydNotificationsOptions ​

Connection String ​

Required. PostgreSQL connection string for notification persistence and template storage.

csharp
options.UsePostgreSqlStorage("Host=localhost;Database=gryd_notifications;...");
// or
options.ConnectionString = "Host=localhost;Database=gryd_notifications;...";

Feature Toggles ​

PropertyTypeDefaultDescription
EnableTemplatesbooltrueEnables Scriban template engine
EnableQueuebooltrueEnables async queue processing. When false, sends synchronously
PersistNotificationsbooltruePersists notifications in the database for auditing
NotificationRetentionDaysint90Days to retain sent/failed notifications before cleanup
csharp
options.EnableTemplates = true;
options.EnableQueue = true;
options.PersistNotifications = true;
options.NotificationRetentionDays = 90;

Email Options ​

Configure email sending via SMTP (MailKit).

csharp
options.Email.DefaultFrom = "noreply@myapp.com";
options.Email.DefaultFromName = "My Application";
options.Email.SmtpHost = "smtp.sendgrid.net";
options.Email.SmtpPort = 587;
options.Email.SmtpUseSsl = true;
options.Email.SmtpUsername = "apikey";
options.Email.SmtpPassword = "SG.xxxxxxxxx";

Properties ​

PropertyTypeDefaultDescription
DefaultFromstring""Default sender email address
DefaultFromNamestring?nullDefault sender display name
SmtpHoststring?nullSMTP server hostname
SmtpPortint587SMTP server port
SmtpUseSslbooltrueUse SSL/TLS for SMTP connection
SmtpUsernamestring?nullSMTP authentication username
SmtpPasswordstring?nullSMTP authentication password
MaxAttachmentSizeMbint10Maximum attachment size per email (MB), checked when the file is attached
MaxAttachmentsPerEmailint5Maximum number of attachments per email
MaxRecipientsPerEmailint50Maximum recipients (To + Cc + Bcc)
BulkBatchSizeint100Emails per batch in bulk operations
BulkDelayBetweenBatchesTimeSpan1sRate limiting delay between batches

Using SendGrid instead of SMTP ​

To use SendGrid's HTTP API instead of SMTP, install the provider package and configure the API key:

csharp
// Install: dotnet add package GrydNotifications.Infrastructure
// SendGrid uses the SMTP credentials with host smtp.sendgrid.net
options.Email.SmtpHost = "smtp.sendgrid.net";
options.Email.SmtpUsername = "apikey";
options.Email.SmtpPassword = "SG.your_api_key_here";

Push Notification Options ​

Configure push notifications via Firebase Cloud Messaging (FCM).

csharp
options.Push.Enabled = true;
options.Push.DefaultTimeToLive = TimeSpan.FromHours(24);
options.Push.AutoRemoveInvalidTokens = true;

Properties ​

PropertyTypeDefaultDescription
EnabledbooltrueEnables the push notification channel
DefaultTimeToLiveTimeSpan24hDefault TTL for push messages
MaxDeviceTokensPerMulticastint500Max tokens per FCM multicast (FCM limit: 500)
StaleTokenThresholdTimeSpan90 daysDuration after which unused tokens are deactivated
AutoRemoveInvalidTokensbooltrueAuto-remove tokens reported as invalid by FCM

Firebase Configuration ​

Place your Firebase service account JSON at the root of your project or configure the GOOGLE_APPLICATION_CREDENTIALS environment variable:

bash
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/firebase-adminsdk.json"

In-App Notification Options ​

Configure the in-app notification channel (drawer/bell notifications + SignalR real-time).

csharp
options.InApp.Enabled = true;
options.InApp.EnableSignalR = true;
options.InApp.HubPath = "/hubs/notifications";
options.InApp.RetentionDays = 90;
options.InApp.MaxUnreadPerUser = 200;

Properties ​

PropertyTypeDefaultDescription
EnabledbooltrueEnables in-app notification channel
RetentionDaysint90Days to retain in-app notifications
MaxUnreadPerUserint200Max unread per user (oldest auto-marked as read)
DefaultTimeToLiveTimeSpan?nullDefault TTL for notifications (null = no expiration)
EnableSignalRbooltrueEnables real-time delivery via SignalR
HubPathstring/hubs/notificationsSignalR hub endpoint path

Retry Options ​

Configure retry policies for failed notification delivery.

csharp
options.Retry.MaxRetries = 3;
options.Retry.BackoffType = BackoffType.Exponential;
options.Retry.BaseDelay = TimeSpan.FromSeconds(5);
options.Retry.MaxDelay = TimeSpan.FromMinutes(5);
options.Retry.UseJitter = true;

Properties ​

PropertyTypeDefaultDescription
MaxRetriesint3Maximum retry attempts before dead-lettering
BackoffTypeBackoffTypeExponentialBackoff strategy
BaseDelayTimeSpan5sBase delay for the first retry
MaxDelayTimeSpan5minMaximum delay cap
UseJitterbooltrueAdds randomized jitter to prevent thundering herd
NonRetryableReasonsHashSet<DeliveryFailureReason>see belowPermanent failures that skip retry

Backoff Types ​

TypeFormulaExample (5s base)
FixedbaseDelay5s → 5s → 5s
LinearbaseDelay × attempt5s → 10s → 15s
ExponentialbaseDelay × 2^attempt5s → 10s → 20s

Non-Retryable Failure Reasons ​

By default, these permanent failures skip retry entirely:

  • InvalidRecipient — Email address doesn't exist
  • InvalidTemplate — Template syntax error
  • AuthenticationFailed — Provider credential error

Queue Options ​

Configure the in-memory notification processing queue (Channel<T>).

csharp
options.Queue.BatchSize = 10;
options.Queue.PollingInterval = TimeSpan.FromSeconds(5);
options.Queue.MaxConcurrency = 4;

Properties ​

PropertyTypeDefaultDescription
BatchSizeint10Notifications dequeued per batch
PollingIntervalTimeSpan5sPolling interval when queue is empty
MaxConcurrencyint4Concurrent processors consuming the queue
MessageExpirationTimeSpan?nullMax time in queue before discard (null = no limit)

WARNING

The default queue uses Channel<T> in-memory. Messages are lost if the application restarts. For durable queuing in production, install GrydNotifications.Scheduling to delegate to GrydJobs.


Health Checks ​

csharp
// Basic registration
builder.Services.AddGrydNotificationsHealthChecks();

// With custom settings
builder.Services.AddGrydNotificationsHealthChecks(
    name: "grydnotifications",
    failureStatus: HealthStatus.Degraded,
    tags: ["grydnotifications", "notifications", "ready"]);

The health check monitors:

  • Queue depth — Returns Degraded if queue depth exceeds 10,000
  • Infrastructure availability — Returns Degraded on exceptions
http
GET /health

{
  "status": "Healthy",
  "entries": {
    "grydnotifications": {
      "status": "Healthy",
      "description": "GrydNotifications is running.",
      "data": {
        "queueDepth": 42
      }
    }
  }
}

appsettings.json Reference ​

Complete configuration example:

json
{
  "ConnectionStrings": {
    "Notifications": "Host=localhost;Database=gryd_notifications;Username=postgres;Password=postgres"
  },
  "GrydNotifications": {
    "EnableTemplates": true,
    "EnableQueue": true,
    "PersistNotifications": true,
    "NotificationRetentionDays": 90,
    "Email": {
      "DefaultFrom": "noreply@myapp.com",
      "DefaultFromName": "My App",
      "SmtpHost": "smtp.sendgrid.net",
      "SmtpPort": 587,
      "SmtpUseSsl": true,
      "SmtpUsername": "apikey",
      "SmtpPassword": "SG.xxxxx",
      "MaxAttachmentSizeMb": 10,
      "MaxAttachmentsPerEmail": 5,
      "MaxRecipientsPerEmail": 50,
      "BulkBatchSize": 100,
      "BulkDelayBetweenBatches": "00:00:01"
    },
    "Push": {
      "Enabled": true,
      "DefaultTimeToLive": "24:00:00",
      "MaxDeviceTokensPerMulticast": 500,
      "StaleTokenThreshold": "90.00:00:00",
      "AutoRemoveInvalidTokens": true
    },
    "InApp": {
      "Enabled": true,
      "RetentionDays": 90,
      "MaxUnreadPerUser": 200,
      "DefaultTimeToLive": null,
      "EnableSignalR": true,
      "HubPath": "/hubs/notifications"
    },
    "Retry": {
      "MaxRetries": 3,
      "BackoffType": "Exponential",
      "BaseDelay": "00:00:05",
      "MaxDelay": "00:05:00",
      "UseJitter": true
    },
    "Queue": {
      "BatchSize": 10,
      "PollingInterval": "00:00:05",
      "MaxConcurrency": 4,
      "MessageExpiration": null
    }
  }
}

Released under the MIT License.