HaidaiTech.Notificator
5.0.0
dotnet add package HaidaiTech.Notificator --version 5.0.0
NuGet\Install-Package HaidaiTech.Notificator -Version 5.0.0
<PackageReference Include="HaidaiTech.Notificator" Version="5.0.0" />
<PackageVersion Include="HaidaiTech.Notificator" Version="5.0.0" />
<PackageReference Include="HaidaiTech.Notificator" />
paket add HaidaiTech.Notificator --version 5.0.0
#r "nuget: HaidaiTech.Notificator, 5.0.0"
#:package HaidaiTech.Notificator@5.0.0
#addin nuget:?package=HaidaiTech.Notificator&version=5.0.0
#tool nuget:?package=HaidaiTech.Notificator&version=5.0.0
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
FriendlyMessagetoNotificationContextMessage: Introduced aFriendlyMessageproperty to improve communication in certain scenarios. Unlike technical messages, aFriendlyMessageis 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 ofNotificationContextfor better performance and maintainability.
Version 3.0.0
- Changed the instantiation of
NotificationContextMessageto use a factory methodCreate()rather than the traditionalnew(). 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 | Versions 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. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.