Nera.Lib.Messaging.Sender 1.0.0

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

Nera.Lib.Messaging.Sender

A robust messaging sender library for Nera applications that provides event-driven communication capabilities with comprehensive logging, retry policies, and template variable substitution.

Features

  • Event-Driven Messaging: Send structured events with metadata and logging
  • Template Variable Support: Dynamic template variable substitution in messages
  • Comprehensive Logging: Track send events with detailed logging entities
  • Retry Policies: Built-in resilience with Polly integration
  • Entity Framework Integration: Persistent event logging with PostgreSQL support
  • Redis Caching: Performance optimization with distributed caching
  • Dependency Injection: Seamless integration with .NET Core DI container

Installation

Install the package via NuGet Package Manager:

dotnet add package Nera.Lib.Messaging.Sender

Or via Package Manager Console:

Install-Package Nera.Lib.Messaging.Sender

Configuration

Add the messaging sender services to your dependency injection container:

using Nera.Lib.Messaging.Sender;

// In your Program.cs or Startup.cs
services.AddNeraMessagingSender(configuration);

Configuration Options

Configure the messaging sender in your appsettings.json:

{
  "NeraMessaging": {
    "Sender": {
      "RetryPolicy": {
        "MaxRetryAttempts": 3,
        "DelayBetweenRetries": "00:00:02"
      },
      "LoggingEnabled": true,
      "CacheSettings": {
        "DefaultExpiration": "00:15:00"
      }
    }
  }
}

Usage

Basic Event Sending

public class NotificationController : ControllerBase
{
    private readonly ISenderService _senderService;

    public NotificationController(ISenderService senderService)
    {
        _senderService = senderService;
    }

    [HttpPost("send-notification")]
    public async Task<IActionResult> SendNotification(NotificationRequest request)
    {
        var metadata = new SendEventMetadata
        {
            TemplateId = "welcome-email",
            Recipient = request.Email,
            Priority = MessagePriority.High
        };

        var templateVariables = new Dictionary<string, object>
        {
            ["UserName"] = request.UserName,
            ["WelcomeMessage"] = "Welcome to our platform!",
            ["ActivationLink"] = request.ActivationUrl
        };

        await _senderService.SendEventAsync(metadata, templateVariables);
        
        return Ok("Notification sent successfully");
    }
}

Working with Template Variables

The library provides a helper for managing template variables:

public class EmailService
{
    private readonly ISenderService _senderService;

    public async Task SendWelcomeEmail(User user)
    {
        var templateHelper = new TemplateVariableHelper();
        
        // Add variables using the helper
        templateHelper.AddVariable("FirstName", user.FirstName);
        templateHelper.AddVariable("LastName", user.LastName);
        templateHelper.AddVariable("CompanyName", "Nextera Systems");
        
        var metadata = new SendEventMetadata
        {
            TemplateId = "user-welcome",
            Recipient = user.Email,
            Subject = "Welcome to Our Platform"
        };

        await _senderService.SendEventAsync(metadata, templateHelper.GetVariables());
    }
}

Event Logging and Tracking

All send events are automatically logged and can be tracked:

public class MessageTrackingService
{
    private readonly ISendEventLogRepository _logRepository;

    public MessageTrackingService(ISendEventLogRepository logRepository)
    {
        _logRepository = logRepository;
    }

    public async Task<IEnumerable<SendEventLogEntity>> GetRecentSendEvents(int hours = 24)
    {
        var since = DateTime.UtcNow.AddHours(-hours);
        return await _logRepository.GetEventsSinceAsync(since);
    }

    public async Task<SendEventLogEntity> GetEventById(Guid eventId)
    {
        return await _logRepository.GetByIdAsync(eventId);
    }
}

Project Structure

Nera.Lib.Messaging.Sender/
├── Common/
│   ├── TemplateVariableHelper.cs      # Helper for managing template variables
│   └── Exceptions/                    # Custom exceptions
├── Entities/
│   └── SendEventLogEntity.cs          # Entity for logging send events
├── Events/
│   ├── SendEventCreatedEvent.cs       # Event raised when send event is created
│   └── SendEventStatusUpdatedEvent.cs # Event raised when send status updates
├── Extensions/
│   └── SendEventMetadataExtensions.cs # Extension methods for metadata
├── Interfaces/
│   ├── ISenderService.cs              # Main sender service interface
│   └── ISendEventLogRepository.cs     # Repository interface for event logs
├── Models/
│   └── SendEventUsageExamples.cs      # Usage examples and documentation
├── Services/
│   └── SenderService.cs               # Main implementation of sender service
├── ValueObjects/
│   └── SendEventMetadata.cs           # Value object for event metadata
└── ServiceCollectionExtensions.cs     # DI container extensions

Events

The library raises the following domain events:

  • SendEventCreatedEvent: Raised when a new send event is created
  • SendEventStatusUpdatedEvent: Raised when the status of a send event changes

Subscribe to these events to implement custom business logic:

public class SendEventHandler : INotificationHandler<SendEventCreatedEvent>
{
    public async Task Handle(SendEventCreatedEvent notification, CancellationToken cancellationToken)
    {
        // Custom logic when send event is created
        Console.WriteLine($"Send event created: {notification.EventId}");
    }
}

Dependencies

This library depends on the following Nera libraries:

  • Nera.Lib.Core (v1.0.1+): Core utilities and base classes
  • Nera.Lib.Domain (v1.0.2+): Domain modeling and DDD patterns
  • Nera.Lib.Caching (v1.0.0+): Caching abstractions and implementations

Requirements

  • .NET 9.0 or later
  • Entity Framework Core 9.0+
  • PostgreSQL database (for event logging)
  • Redis (optional, for caching)

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For questions and support, please contact the Nextera Systems development team or create an issue in the repository.


Nextera Systems - Building robust, scalable applications with .NET

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 159 9/9/2025