Indiko.Blocks.Messaging.Abstractions 2.1.2

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

Indiko.Blocks.Messaging.Abstractions

Core abstractions for messaging services including email, SMS, and push notifications with template engine support.

Overview

This package provides fundamental contracts for implementing messaging systems across different channels (email, SMS, push notifications) with built-in template processing and placeholder replacement.

Features

  • IMessageSender<T>: Generic message sender interface
  • IMessage: Message contract
  • ISendResult: Send result abstraction
  • Template Engine: Built-in template processing
  • Placeholder Replacement: Dynamic content replacement in templates
  • Multi-Channel: Support for email, SMS, push notifications
  • Async/Await: Full asynchronous support

Installation

dotnet add package Indiko.Blocks.Messaging.Abstractions

Key Interfaces

IMessageSender<T>

Generic interface for sending messages.

public interface IMessageSender<T> where T : ISendResult
{
    Task<T> SendAsync(IMessage message, CancellationToken cancellationToken = default);
}

IMessage

Base interface for all message types.

public interface IMessage
{
    string Subject { get; }
    string Body { get; }
    Dictionary<string, string> Metadata { get; }
}

ISendResult

Result of a send operation.

public interface ISendResult
{
    bool Success { get; }
    string MessageId { get; }
    string ErrorMessage { get; }
}

Template Engine

ITemplateEngine

Process templates with placeholder replacement.

public interface ITemplateEngine
{
    string ProcessTemplate(string template, Dictionary<string, string> placeholders);
    Task<string> ProcessTemplateAsync(string templatePath, Dictionary<string, string> placeholders);
}

Usage Example

public class EmailService
{
    private readonly ITemplateEngine _templateEngine;
    private readonly IMessageSender<EmailSendResult> _emailSender;

    public async Task SendWelcomeEmailAsync(string email, string firstName)
    {
        // Load template
        var template = await File.ReadAllTextAsync("Templates/WelcomeEmail.html");
        
        // Define placeholders
        var placeholders = new Dictionary<string, string>
        {
            { "FirstName", firstName },
            { "Year", DateTime.Now.Year.ToString() },
            { "SupportEmail", "support@example.com" }
        };
        
        // Process template
        var body = _templateEngine.ProcessTemplate(template, placeholders);
        
        // Create message
        var message = new EmailMessage
        {
            To = email,
            Subject = $"Welcome, {firstName}!",
            Body = body,
            IsHtml = true
        };
        
        // Send
        var result = await _emailSender.SendAsync(message);
        
        if (!result.Success)
        {
            _logger.LogError($"Failed to send email: {result.ErrorMessage}");
        }
    }
}

Placeholder Replacement

IPlaceholderReplacer

Replace placeholders in text.

public interface IPlaceholderReplacer
{
    string Replace(string text, Dictionary<string, string> placeholders);
}

Placeholder Syntax

Supports multiple placeholder formats:

{{FirstName}}           - Double curly braces
{FirstName}             - Single curly braces
[FirstName]             - Square brackets
$FirstName$             - Dollar signs
%FirstName%             - Percent signs

Example Templates

Email Template (HTML):

<!DOCTYPE html>
<html>
<head>
    <title>Welcome Email</title>
</head>
<body>
    <h1>Welcome, {{FirstName}}!</h1>
    <p>Thank you for joining us, {{FirstName}} {{LastName}}.</p>
    <p>Your account was created on {{SignupDate}}.</p>
    <p>If you have questions, contact us at {{SupportEmail}}.</p>
    <p>&copy; {{Year}} {{CompanyName}}. All rights reserved.</p>
</body>
</html>

SMS Template:

Hi {{FirstName}}, welcome to {{CompanyName}}! 
Your verification code is: {{VerificationCode}}
This code expires in {{ExpiryMinutes}} minutes.

Push Notification Template:

{
  "title": "New Message from {{SenderName}}",
  "body": "{{MessagePreview}}",
  "data": {
    "messageId": "{{MessageId}}",
    "senderId": "{{SenderId}}"
  }
}

Message Types

Email Message

public class EmailMessage : IMessage
{
    public string To { get; set; }
    public string From { get; set; }
    public string Subject { get; set; }
    public string Body { get; set; }
    public bool IsHtml { get; set; }
    public List<string> Cc { get; set; }
    public List<string> Bcc { get; set; }
    public List<Attachment> Attachments { get; set; }
    public Dictionary<string, string> Metadata { get; set; }
}

SMS Message

public class SmsMessage : IMessage
{
    public string To { get; set; }
    public string From { get; set; }
    public string Subject { get; set; } = string.Empty;
    public string Body { get; set; }
    public Dictionary<string, string> Metadata { get; set; }
}

Push Notification Message

public class PushNotificationMessage : IMessage
{
    public string[] DeviceTokens { get; set; }
    public string Subject { get; set; }
    public string Body { get; set; }
    public string Title { get; set; }
    public Dictionary<string, string> Data { get; set; }
    public Dictionary<string, string> Metadata { get; set; }
}

Send Results

Email Send Result

public class EmailSendResult : ISendResult
{
    public bool Success { get; set; }
    public string MessageId { get; set; }
    public string ErrorMessage { get; set; }
    public DateTime SentAt { get; set; }
    public List<string> FailedRecipients { get; set; }
}

SMS Send Result

public class SmsSendResult : ISendResult
{
    public bool Success { get; set; }
    public string MessageId { get; set; }
    public string ErrorMessage { get; set; }
    public decimal Cost { get; set; }
    public int SegmentCount { get; set; }
}

Template Processing Examples

Simple Text Replacement

var template = "Hello {{Name}}, your order #{{OrderId}} has been shipped!";

var placeholders = new Dictionary<string, string>
{
    { "Name", "John Doe" },
    { "OrderId", "12345" }
};

var result = _templateEngine.ProcessTemplate(template, placeholders);
// Result: "Hello John Doe, your order #12345 has been shipped!"

Conditional Content

var template = @"
Dear {{CustomerName}},

{{#IsPremium}}
As a premium member, you get free shipping!
{{/IsPremium}}

{{^IsPremium}}
Upgrade to premium for free shipping.
{{/IsPremium}}

Best regards,
{{CompanyName}}
";

var placeholders = new Dictionary<string, string>
{
    { "CustomerName", "Jane Smith" },
    { "IsPremium", "true" },
    { "CompanyName", "Acme Corp" }
};

Lists and Loops

var template = @"
Order Summary for {{CustomerName}}:

{{#Items}}
- {{Name}}: ${{Price}} x {{Quantity}} = ${{Total}}
{{/Items}}

Total: ${{OrderTotal}}
";

Best Practices

  1. Template Storage: Store templates in files or database
  2. Validation: Validate placeholders before sending
  3. Error Handling: Always check ISendResult.Success
  4. Logging: Log all send operations
  5. Rate Limiting: Implement rate limiting for bulk sends
  6. Retries: Implement retry logic for transient failures
  7. Testing: Test templates with various placeholder values

Configuration

MessagingOptions

public class MessagingOptions
{
    public bool Enabled { get; set; } = true;
    public string TemplateDirectory { get; set; } = "Templates";
    public string DefaultFrom { get; set; }
    public int MaxRetries { get; set; } = 3;
    public TimeSpan RetryDelay { get; set; } = TimeSpan.FromSeconds(5);
}

Configuration Example

{
  "MessagingOptions": {
    "Enabled": true,
    "TemplateDirectory": "EmailTemplates",
    "DefaultFrom": "noreply@example.com",
    "MaxRetries": 3,
    "RetryDelay": "00:00:05"
  }
}

Testing

Mock Message Sender

public class MockMessageSender : IMessageSender<EmailSendResult>
{
    public Task<EmailSendResult> SendAsync(
        IMessage message, 
        CancellationToken cancellationToken = default)
    {
        // For testing - don't actually send
        return Task.FromResult(new EmailSendResult
        {
            Success = true,
            MessageId = Guid.NewGuid().ToString(),
            SentAt = DateTime.UtcNow
        });
    }
}

Target Framework

  • .NET 10

Dependencies

  • Indiko.Blocks.Common.Abstractions

License

See LICENSE file in the repository root.

  • Indiko.Blocks.Messaging.EMail - Email implementation
  • Indiko.Blocks.Messaging.PushNotification - Push notification implementation
  • Indiko.Blocks.Messaging.AzureNotificationHub - Azure Notification Hub implementation
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Indiko.Blocks.Messaging.Abstractions:

Package Downloads
Indiko.Blocks.Messaging.EMail

Building Blocks Messaging EMail

Indiko.Blocks.Messaging.AzureNotificationHub

Building Blocks Messaging Azure Notification Hub

Indiko.Blocks.Messaging.PushNotification

Building Blocks Messaging Push Notification for Google FCN and Apple APNS

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.2 330 12/18/2025
2.1.1 715 12/2/2025
2.1.0 694 12/2/2025
2.0.0 305 9/17/2025
1.7.23 364 9/8/2025
1.7.22 218 9/8/2025
1.7.21 231 8/14/2025
1.7.20 247 6/23/2025
1.7.19 227 6/3/2025
1.7.18 234 5/29/2025
1.7.17 220 5/26/2025
1.7.15 164 4/12/2025
1.7.14 195 4/11/2025
1.7.13 201 3/29/2025
1.7.12 221 3/28/2025
1.7.11 222 3/28/2025
1.7.10 221 3/28/2025
1.7.9 206 3/28/2025
1.7.8 213 3/28/2025
1.7.5 241 3/17/2025
1.7.4 212 3/16/2025
1.7.3 217 3/16/2025
1.7.2 213 3/16/2025
1.7.1 276 3/11/2025
1.6.8 241 3/11/2025
1.6.7 294 3/4/2025
1.6.6 172 2/26/2025
1.6.5 196 2/20/2025
1.6.4 191 2/20/2025
1.6.3 203 2/5/2025
1.6.2 181 1/24/2025
1.6.1 175 1/24/2025
1.6.0 166 1/16/2025
1.5.2 183 1/16/2025
1.5.1 237 11/3/2024
1.5.0 197 10/26/2024
1.3.2 199 10/24/2024
1.3.0 207 10/10/2024
1.2.5 209 10/9/2024
1.2.4 210 10/8/2024
1.2.1 196 10/3/2024
1.2.0 190 9/29/2024
1.1.1 201 9/23/2024
1.1.0 223 9/18/2024
1.0.33 232 9/15/2024
1.0.28 211 8/28/2024
1.0.27 224 8/24/2024
1.0.26 220 7/7/2024
1.0.25 176 7/6/2024
1.0.24 186 6/25/2024
1.0.23 220 6/1/2024
1.0.22 199 5/14/2024
1.0.21 195 5/14/2024
1.0.20 228 4/8/2024
1.0.19 223 4/3/2024
1.0.18 217 3/23/2024
1.0.17 242 3/19/2024
1.0.16 218 3/19/2024
1.0.15 228 3/11/2024
1.0.14 218 3/10/2024
1.0.13 221 3/6/2024
1.0.12 225 3/1/2024
1.0.11 221 3/1/2024
1.0.10 218 3/1/2024
1.0.9 208 3/1/2024
1.0.8 219 2/19/2024
1.0.7 205 2/17/2024
1.0.6 224 2/17/2024
1.0.5 211 2/17/2024
1.0.4 217 2/7/2024
1.0.3 222 2/6/2024
1.0.1 182 2/6/2024
1.0.0 259 1/9/2024
1.0.0-preview99 243 12/22/2023
1.0.0-preview98 200 12/21/2023
1.0.0-preview97 184 12/21/2023
1.0.0-preview96 201 12/20/2023
1.0.0-preview95 171 12/20/2023
1.0.0-preview94 166 12/18/2023
1.0.0-preview93 197 12/13/2023
1.0.0-preview92 203 12/13/2023
1.0.0-preview91 201 12/12/2023
1.0.0-preview90 172 12/11/2023
1.0.0-preview89 191 12/11/2023
1.0.0-preview88 218 12/6/2023
1.0.0-preview87 204 12/6/2023
1.0.0-preview86 214 12/6/2023
1.0.0-preview85 193 12/6/2023
1.0.0-preview84 209 12/5/2023
1.0.0-preview83 216 12/5/2023
1.0.0-preview82 209 12/5/2023
1.0.0-preview81 196 12/4/2023
1.0.0-preview80 195 12/1/2023
1.0.0-preview77 189 12/1/2023
1.0.0-preview76 198 12/1/2023
1.0.0-preview75 200 12/1/2023
1.0.0-preview74 223 11/26/2023
1.0.0-preview73 200 11/7/2023
1.0.0-preview72 219 11/6/2023
1.0.0-preview71 224 11/3/2023
1.0.0-preview70 211 11/2/2023
1.0.0-preview69 193 11/2/2023
1.0.0-preview68 195 11/2/2023
1.0.0-preview67 218 11/2/2023
1.0.0-preview66 192 11/2/2023
1.0.0-preview65 202 11/2/2023
1.0.0-preview64 219 11/2/2023
1.0.0-preview63 204 11/2/2023
1.0.0-preview62 218 11/1/2023
1.0.0-preview61 193 11/1/2023
1.0.0-preview60 201 11/1/2023
1.0.0-preview59 204 11/1/2023
1.0.0-preview58 206 10/31/2023
1.0.0-preview57 202 10/31/2023
1.0.0-preview56 215 10/31/2023
1.0.0-preview55 204 10/31/2023
1.0.0-preview54 221 10/31/2023
1.0.0-preview53 196 10/31/2023
1.0.0-preview52 214 10/31/2023
1.0.0-preview51 191 10/31/2023
1.0.0-preview50 204 10/31/2023
1.0.0-preview48 186 10/31/2023
1.0.0-preview46 195 10/31/2023
1.0.0-preview45 197 10/31/2023
1.0.0-preview44 207 10/31/2023
1.0.0-preview43 193 10/31/2023
1.0.0-preview42 193 10/30/2023
1.0.0-preview41 198 10/30/2023
1.0.0-preview40 207 10/27/2023
1.0.0-preview39 192 10/27/2023
1.0.0-preview38 202 10/27/2023
1.0.0-preview37 194 10/27/2023
1.0.0-preview36 212 10/27/2023
1.0.0-preview35 199 10/27/2023
1.0.0-preview34 186 10/27/2023
1.0.0-preview33 212 10/26/2023
1.0.0-preview32 206 10/26/2023
1.0.0-preview31 209 10/26/2023
1.0.0-preview30 205 10/26/2023
1.0.0-preview29 208 10/26/2023
1.0.0-preview28 222 10/26/2023
1.0.0-preview27 202 10/26/2023
1.0.0-preview26 227 10/25/2023
1.0.0-preview25 213 10/23/2023
1.0.0-preview24 180 10/23/2023
1.0.0-preview23 177 10/23/2023
1.0.0-preview101 194 1/5/2024