HaidaiTech.Notificator 5.0.0

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

Haidai Notificator

Haidai Notificator is a project developed by the Haidai team, implementing the Notification Pattern as described by Martin Fowler here.

Release Versions

  • 5.0.0: The project was updated to .NET 10

Release Notes

Version 4.0.0

  • Added FriendlyMessage to NotificationContextMessage: Introduced a FriendlyMessage property to improve communication in certain scenarios. Unlike technical messages, a FriendlyMessage is tailored for users or systems, making it more appropriate for display without exposing sensitive details. This approach enhances security by preventing the disclosure of internal issues.

  • Optimized NotificationContext: Improved the internal implementation of NotificationContext for better performance and maintainability.

Version 3.0.0

  • Changed the instantiation of NotificationContextMessage to use a factory method Create() rather than the traditional new(). This breaking change provides better control over how instances of the class are created and managed.

Version 2.1.0

This release introduces an extension method that injects NotificationContext into the dependency injection container. Now you can do:

// ASP.NET Core 

// Program.cs

using HaidaiTech.Notificator.Interfaces;
using HaidaiTech.Notificator.NotificationContextMessages;
using HaidaiTech.Notificator.NotificationContextPattern;
using HaidaiTech.Notificator.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container. In this case, NotificationContextMessage will be used

builder.Services.AddNotificationContextService();

//using your own notification context message
builder.Services.AddNotificationContextService<MyCustomNotificationContextMessage>();

//if you want to use your own DI, use this

builder.Services.AddScoped<INotificationContext<NotificationContextMessage>, NotificationContext<NotificationContextMessage>>();

//or 
builder.Services.AddScoped<INotificationContext<MyCustomNotificationContextMessage>, NotificationContext<MyCustomNotificationContextMessage>>();


//Console Application

using System;
using Microsoft.Extensions.DependencyInjection;
using HaidaiTech.Notificator.Interfaces;
using HaidaiTech.Notificator.NotificationContextMessages;
using HaidaiTech.Notificator.NotificationContextPattern;
using HaidaiTech.Notificator.Extensions;

public class MyCustomNotificationContextMessage : INotificationContextMessage
{
    public string Message { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        var serviceCollection = new ServiceCollection();
        ConfigureServices(serviceCollection);

        var serviceProvider = serviceCollection.BuildServiceProvider();

        var notificationContext = serviceProvider.GetService<INotificationContext<MyCustomNotificationContextMessage>>();

        var notification = new MyCustomNotificationContextMessage { Message = "Nova notificação" };
        notificationContext.AddNotification(notification);

        if (notificationContext.HasNotifications())
        {
            Console.WriteLine("Existem notificações.");
        }
    }

    private static void ConfigureServices(IServiceCollection services)
    {
        services.AddNotificationContextService<MyCustomNotificationContextMessage>();
    }
}

// Worker

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using HaidaiTech.Notificator.Interfaces;
using HaidaiTech.Notificator.NotificationContextMessages;
using HaidaiTech.Notificator.NotificationContextPattern;
using HaidaiTech.Notificator.Extensions;

public class MyCustomNotificationContextMessage : INotificationContextMessage
{
    public string Message { get; set; }
}

public class Worker : BackgroundService
{
    private readonly INotificationContext<MyCustomNotificationContextMessage> _notificationContext;

    public Worker(INotificationContext<MyCustomNotificationContextMessage> notificationContext)
    {
        _notificationContext = notificationContext;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            var notification = new MyCustomNotificationContextMessage { Message = "Nova notificação" };
            _notificationContext.AddNotification(notification);

            if (_notificationContext.HasNotifications())
            {
                Console.WriteLine("Existem notificações.");
            }

            await Task.Delay(1000, stoppingToken);
        }
    }
}

class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureServices((hostContext, services) =>
            {
                services.AddNotificationContextService<MyCustomNotificationContextMessage>();
                services.AddHostedService<Worker>();
            });
}

This project follow the TDD pattern. If you read the tests, you will understand the using of NotificationContext class.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
5.0.0 474 11/18/2025
4.0.2 317 8/25/2025
4.0.1 223 2/14/2025
4.0.0 239 11/20/2024
3.0.0 263 9/11/2024
2.1.0 287 2/10/2024
2.0.0 315 12/25/2023
1.3.1 243 8/27/2023
1.2.1 258 8/19/2023
1.1.1 246 8/19/2023
1.0.1 257 8/15/2023
1.0.0 264 8/10/2023