Tooark.Notifications
4.11.0
dotnet add package Tooark.Notifications --version 4.11.0
NuGet\Install-Package Tooark.Notifications -Version 4.11.0
<PackageReference Include="Tooark.Notifications" Version="4.11.0" />
<PackageVersion Include="Tooark.Notifications" Version="4.11.0" />
<PackageReference Include="Tooark.Notifications" />
paket add Tooark.Notifications --version 4.11.0
#r "nuget: Tooark.Notifications, 4.11.0"
#:package Tooark.Notifications@4.11.0
#addin nuget:?package=Tooark.Notifications&version=4.11.0
#tool nuget:?package=Tooark.Notifications&version=4.11.0
Tooark.Notifications
Library for creating and managing notifications and alerts, easing communication and monitoring in .NET projects.
π Docs: Tooark.Notifications on the site Β· All packages Β· API reference
π Languages: πΊπΈ English (this file) Β· π§π· PortuguΓͺs
π Contents
π§ Installation
dotnet add package Tooark.Notifications
The package has no configuration. Notification is used through inheritance, in classes that accumulate
the result of several checks β such as the Tooark value objects and entities β, and the mutators are
protected: the object itself accumulates the notification, not whoever consumes it. For items that already
exist, coming from outside the object, there is NotificationList (since v4.11.0), created directly from them.
Messages are stored as a key, not as final text. Translation is done by the layer that builds the
response, such as the ResponseDto of Tooark.Dtos.
π§± Classes
The available classes are:
1. Notification Item
Purpose: Represents the structure of a notification item with message, key and error code. The values are normalized on construction and the instance is read-only.
Properties:
Message: The notification message.Key: The notification key.Code: The notification error code.
Methods:
NotificationItem(string? message): Creates a new instance with theUnknownkey and theT.ERRcode.NotificationItem(string? message, string? key): Creates a new instance with the given key and theT.ERRcode.NotificationItem(string? message, string? key, string? code): Creates a new instance with the given key and code.
The three parameters accept a missing value because the constructor already handled it: a blank message
becomes Notifications.MessageNullEmpty, a blank key becomes Unknown and a blank code becomes T.ERR.
The signature declared non-nullable while the body checked for null β whoever passed a string? got a
compiler warning for a path that always worked.
ToString(): Returns the notification message.string: Implicitly converts aNotificationIteminstance to a string, returning the message. A null instance returns an empty string.NotificationItem: Implicitly converts a string to aNotificationIteminstance, with theUnknownkey and theT.ERRcode.
Value normalization:
| Parameter | Null, empty or blank | Other values |
|---|---|---|
message |
Notifications.MessageNullEmpty |
Leading and trailing whitespace removed |
key |
Unknown |
All whitespace removed, including tabs and line breaks |
code |
T.ERR |
Leading and trailing whitespace removed |
2. Notification
Purpose:
Abstract class that manages the notification list of the object inheriting it. It is the base of ValueObject, BaseEntity and Validation.
Creating and clearing notifications is protected: only the object itself decides what it notifies. Aggregating existing notifications is public, allowing the validation result of other objects to be composed.
Properties:
Notifications: Returns the read-only list of notifications.IsValid: Returns true if the notification list is empty.Count: Returns the number of notifications.Codes: Returns the list of error codes of the notifications.Keys: Returns the list of keys of the notifications.Messages: Returns the list of messages of the notifications.
Public methods:
AddNotifications(Notification notification): Adds the notifications of another notification to the notification list.AddNotifications(params Notification[] notifications): Adds the notifications of a collection of notifications to the notification list.
Protected methods:
AddNotification(NotificationItem notification): Adds a notification item to the notification list.AddNotification(Type property, string message): Adds a notification item using the type name as key.AddNotification(Type property, string message, string code): Adds a notification item using the type name as key, with an error code.AddNotification(string message, string key): Adds a notification item with message and key.AddNotification(string message, string key, string code): Adds a notification item with message, key and error code.AddNotifications(ICollection<NotificationItem> notifications): Adds a collection of notification items to the notification list.ClearNotifications(): Clears the notification list.Clear(): Same asClearNotifications(). Obsolete since v4.8.0, removed in v5: the name collides with domain methods of the entities (aClear()of your own hides the base one,CS0108). It is marked with[Obsolete], so calls get a compiler warning; replace them withClearNotifications().
Null handling:
| Situation | Behavior |
|---|---|
Null argument in AddNotification or AddNotifications |
Adds the Notifications.NotificationNull notification |
| Null item inside a collection | Ignored, without changing the list |
Adding the instance itself in AddNotifications |
No effect, the list is not changed |
3. Notification List
Purpose:
Sealed class NotificationList, available since v4.11.0: a concrete notification, created from items that already exist. It inherits from Notification, so it has the same properties and is accepted wherever a Notification is expected.
Notification only takes items through protected methods, because the object itself is the one that notifies. NotificationList covers the case where the items come from outside the object and need to travel as a notification: the field errors of a validation, the errors returned by another service, a list built by the application.
The exceptions of Tooark.Exceptions accept a Notification and preserve the key and the code of each item, so new BadRequestException(new NotificationList(items)) carries the whole list to the response.
Methods:
NotificationList(IEnumerable<NotificationItem> notifications): Creates the notification with the given items, in the order they came, keeping the message, the key and the code of each one. The sequence is enumerated only once.
Items go in through the constructor only: there is no public method to add an item afterwards. Public aggregation (AddNotifications) remains available, as in any Notification.
Null handling:
| Situation | Behavior |
|---|---|
| Null collection | Throws ArgumentNullException |
| Null item inside the collection | Ignored, without changing the list |
| Empty collection | Notification without items, IsValid true |
4. Error Messages
Purpose:
Static class NotificationErrorMessages with the messages generated by the library itself. They are translation keys, not final texts.
| Constant | Value | When it occurs |
|---|---|---|
MessageIsNullOrEmpty |
Notifications.MessageNullEmpty |
Null, empty or whitespace-only message |
NotificationIsNull |
Notifications.NotificationNull |
Notification or collection received as argument is null |
π Usage Examples
Notification Item
// Message, with the 'Unknown' key and the 'T.ERR' code
var notification1 = new NotificationItem("Example message");
// Message and key, with the 'T.ERR' code
var notification2 = new NotificationItem("Example message", "ExampleKey");
// Message, key and code
var notification3 = new NotificationItem("Example message", "ExampleKey", "XPTO1");
// The key has its whitespace removed
var notification4 = new NotificationItem("Example message", "Example Key");
var key = notification4.Key; // "ExampleKey"
Notification
// Adding notifications is protected: only the object itself notifies its errors
public class MyNotification : Notification
{
public void NotifyError(string message)
{
AddNotification(message, "Error", "XPTO1");
}
}
var myNotification = new MyNotification();
myNotification.NotifyError("An error occurred.");
var isValid = myNotification.IsValid; // False
var count = myNotification.Count; // 1
var codes = myNotification.Codes; // ["XPTO1"]
var keys = myNotification.Keys; // ["Error"]
var messages = myNotification.Messages; // ["An error occurred."]
var notifications = myNotification.Notifications; // [NotificationItem { Message = "An error occurred.", Key = "Error", Code = "XPTO1" }]
// Aggregation is public: existing notifications can be composed from outside the object
public class MyValidation : Notification
{ }
var validation = new MyValidation();
validation.AddNotifications(myNotification, myOtherNotification);
Notification List
// Items that already exist, coming from outside the object: field errors of a validation, errors from another service
NotificationItem[] items =
[
new("Email is required.", "Email", "XPTO1"),
new("Name is too short.", "Name", "XPTO2")
];
var list = new NotificationList(items);
var isValid = list.IsValid; // False
var count = list.Count; // 2
var codes = list.Codes; // ["XPTO1", "XPTO2"]
var keys = list.Keys; // ["Email", "Name"]
var messages = list.Messages; // ["Email is required.", "Name is too short."]
// An empty list is a valid notification, without items
var empty = new NotificationList([]);
var emptyIsValid = empty.IsValid; // True
// The list is a Notification: another notification aggregates it, and a Tooark.Exceptions exception takes it
validation.AddNotifications(list);
throw new BadRequestException(list);
π€ Contributing
Contributions are welcome! Start with CONTRIBUTING.md β it covers the development workflow, the coding and commit conventions and the pull request checklist. Bugs and feature requests go through the issue templates of the Tooark repository.
By participating you agree to the Code of Conduct.
π Help & Security
- β Questions, bugs, feature ideas β see SUPPORT.md for the right channel
- π Security vulnerabilities β do not open a public issue; follow SECURITY.md
π Support
If Tooark helps your projects, consider supporting its development:
- π GitHub Sponsors
- β Ko-fi
Every contribution helps keep the project maintained and improving. Thank you! π
π License
This project is licensed under the BSD 3-Clause License.
| Product | Versions 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 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. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Tooark.Notifications:
| Package | Downloads |
|---|---|
|
Tooark.Exceptions
Package for creating exceptions for .NET applications. |
|
|
Tooark.Validations
Package for managing validations and standards for .NET applications. |
|
|
Tooark.ValueObjects
Package for managing predefined and validated Value Objects for .NET applications. |
|
|
Tooark.Entities
Package for managing base entities in .NET applications. |
|
|
Tooark.Dtos
Package for managing base DTOs in .NET applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.11.0 | 200 | 11/21/2026 |
| 4.10.0 | 522 | 11/18/2026 |
| 4.9.0 | 587 | 11/16/2026 |
| 4.8.0 | 569 | 11/15/2026 |
| 4.7.3 | 511 | 11/11/2026 |
| 4.7.2 | 517 | 11/3/2026 |
| 4.7.1 | 582 | 10/17/2026 |
| 4.7.0 | 834 | 9/30/2026 |
| 4.6.0 | 374 | 9/29/2026 |
| 4.5.0 | 350 | 9/29/2026 |
| 4.4.0 | 344 | 9/28/2026 |
| 4.3.0 | 363 | 9/26/2026 |
| 4.2.1 | 354 | 9/25/2026 |
| 4.2.0 | 379 | 9/20/2026 |
| 4.1.0 | 336 | 9/18/2026 |
| 4.0.1 | 397 | 8/25/2026 |
| 3.3.7 | 332 | 11/15/2026 |
| 3.3.6 | 313 | 9/18/2026 |
| 2.3.6 | 286 | 11/15/2026 |
| 2.3.5 | 257 | 9/18/2026 |