Decode.Notifications 3.0.0

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

Decode.Notifications

A simple and lightweight library for domain notifications using the notification pattern in .NET.

📦 Installation

dotnet add package Decode.Notifications

🛠️ Usage

1. Dependency Injection Configuration

In your Program.cs or Startup.cs:

using Decode.Notifications.Extensions;

// You can use AddDomainNotifications() or the alias AddDecodeNotifications()
builder.Services.AddDomainNotifications();

2. Using in Services or Domain Logic

public class UserService
{
    private readonly IDomainNotificationContext _notificationContext;

    public UserService(IDomainNotificationContext notificationContext)
    {
        _notificationContext = notificationContext;
    }

    public void RegisterUser(string username)
    {
        if (string.IsNullOrWhiteSpace(username))
        {
            _notificationContext.Add("Username is required.", HttpStatusCode.BadRequest, nameof(username));
            return;
        }

        // Logic...
    }
}

3. The DomainNotification Model & Context Operations

Under the hood, notifications are stored as DomainNotification objects in the context.

DomainNotification Class Structure
  • Message (string): The validation or error message.
  • StatusCode (int): The HTTP status code representation (defaults to 400).
  • Key (string?): Optional parameter representing the field name or key (e.g. nameof(username)).
Additional Context Methods

You can also add individual notifications directly or batch multiple notifications:

// Add an explicit DomainNotification object
_notificationContext.Add(new DomainNotification("Email is invalid", 422, "Email"));

// Add a collection of DomainNotifications at once (useful for batch validations)
List<DomainNotification> notificationBatch =
[
    new DomainNotification("Password is too short", 400, "Password"),
    new DomainNotification("Password must contain a number", 400, "Password")
];
_notificationContext.AddRange(notificationBatch);

// Retrieve all raw notifications currently in the context
IReadOnlyCollection<DomainNotification> rawNotifications = _notificationContext.Notifications;
GetStatusCode() returns the highest code, not the first

With notifications carrying different status codes, GetStatusCode() returns the maximum, and 200 OK when the context is empty. So a 400 and a 422 together yield 422. That is a deliberate choice — the more specific code wins — but it means the response code does not necessarily match the first notification added.

4. Handling Notifications in Controllers/Middleware

[ApiController]
[Route("[controller]")]
public class UsersController : ControllerBase
{
    private readonly IDomainNotificationContext _notificationContext;

    public UsersController(IDomainNotificationContext notificationContext)
    {
        _notificationContext = notificationContext;
    }

    [HttpPost]
    public IActionResult Create(UserDto user)
    {
        // Call service...

        if (_notificationContext.HasNotifications)
        {
            return StatusCode(_notificationContext.GetStatusCode(), _notificationContext.GetMessages());
        }

        return Ok();
    }
}

📄 License

MIT License.

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 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 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 (2)

Showing the top 2 NuGet packages that depend on Decode.Notifications:

Package Downloads
Decode.AspNetCore

ASP.NET Core extensions for the Decode ecosystem, including global exception handling and base controllers.

Decode.Notifications.FluentValidation

FluentValidation extensions for Decode Notifications library.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 124 9/14/2026
2.1.0 136 9/13/2026
2.0.2 134 9/13/2026
2.0.1 137 9/13/2026
2.0.0 168 7/28/2026
1.0.3 185 6/19/2026
1.0.2 188 5/26/2026
1.0.1 172 4/25/2026