PMQ.Notifications 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package PMQ.Notifications --version 1.0.4
                    
NuGet\Install-Package PMQ.Notifications -Version 1.0.4
                    
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="PMQ.Notifications" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PMQ.Notifications" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="PMQ.Notifications" />
                    
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 PMQ.Notifications --version 1.0.4
                    
#r "nuget: PMQ.Notifications, 1.0.4"
                    
#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 PMQ.Notifications@1.0.4
                    
#: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=PMQ.Notifications&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=PMQ.Notifications&version=1.0.4
                    
Install as a Cake Tool

PMQ.Notifications

A package for managing notifications and validations in .NET applications, making it easy to control messages, errors, and business rules in a centralized and strongly-typed way.

Installation

You can install via NuGet:

dotnet add package PMQ.Notifications

Or manually add the reference in your .csproj.

How it works

The package provides a notification context (NotificationContext) to register, query, and handle validation messages, business rules, access errors, and more, using strongly-typed notification types (NotificationType).

Main components

  • NotificationContext: Manages the list of notifications.
  • Notification: Represents a single notification (with key, message, and optional type).
  • NotificationType: Enum-like value object for typed categorization of messages.

Usage Examples

Adding notifications

var context = new NotificationContext();

// Add a simple notification
context.Add("Required field not provided.");

// Add with type
context.Add("Invalid email.", NotificationType.Validation);

// Add with custom key
context.Add("Email", "Email already registered.", NotificationType.BusinessRule);

// Add multiple notifications
context.AddRange(new[] {
    new Notification("Weak password.", NotificationType.Validation),
    new Notification("User not found.", NotificationType.NotFound)
});

Querying notifications

// All notifications
var all = context.Notifications;

// Check if any notification exists
if (context.HasNotifications)
{
    // handle logic
}

// Filter by type
var validations = context.GetByType(NotificationType.Validation);

// Check for a specific type
if (context.HasType(NotificationType.NotFound))
{
    // custom handling
}

// Get only the messages
var messages = context.GetMessages();
var validationMessages = context.GetMessages(NotificationType.Validation);

Clearing notifications

context.Clear();

Usage in Filters and status code manipulation

NotificationContext can be injected and used in filters (e.g., IActionFilter or IExceptionFilter) to customize HTTP responses based on the notification type.

public class NotificationFilter : IActionFilter
{
    private readonly NotificationContext _context;

    public NotificationFilter(NotificationContext context) => _context = context;

    public void OnActionExecuting(ActionExecutingContext context) { }

    public void OnActionExecuted(ActionExecutedContext context)
    {
        if (_context.HasType(NotificationType.Validation))
        {
            context.Result = new BadRequestObjectResult(_context.GetMessages(NotificationType.Validation));
        }
        else if (_context.HasType(NotificationType.NotFound))
        {
            context.Result = new NotFoundObjectResult(_context.GetMessages(NotificationType.NotFound));
        }
        else if (_context.HasNotifications)
        {
            context.Result = new UnprocessableEntityObjectResult(_context.GetMessages());
        }
    }
}

Handling responses with NotificationType

Use NotificationType to centralize and standardize business logic across your services, application, and API layers.

It enables better separation of concerns, allows easier unit testing, and makes your response logic explicit and reusable.

Documentation

For more details, explore the source code and XML comments. Everything is written in a clean and extensible way, ready for your use and contribution.

MIT License © 2025 Pablo Mickael Quevedo

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

    • No dependencies.

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.6 123 8/31/2025
1.0.4 59 8/3/2025
1.0.0 61 8/3/2025