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 335 12/18/2025
2.1.1 718 12/2/2025
2.1.0 700 12/2/2025
2.0.0 308 9/17/2025
1.7.23 366 9/8/2025
1.7.22 220 9/8/2025
1.7.21 234 8/14/2025
1.7.20 251 6/23/2025
1.7.19 231 6/3/2025
1.7.18 241 5/29/2025
1.7.17 223 5/26/2025
1.7.15 167 4/12/2025
1.7.14 198 4/11/2025
1.7.13 205 3/29/2025
1.7.12 226 3/28/2025
1.7.11 225 3/28/2025
1.7.10 222 3/28/2025
1.7.9 210 3/28/2025
1.7.8 218 3/28/2025
1.7.5 244 3/17/2025
Loading failed