DevSource.Stack.Notifications 2.0.0

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

<div align="center"> <img src="https://github.com/uitanmaciel/devsource-stack-notifications/blob/main/src/DevSource.Stack.Notifications/devsource-icon.jpeg" width="130" />
</div>

DevSource.Stack.Notifications

This library is an implementation for application-level Notifications, designed to facilitate error handling and validation in a systematic and flexible way, allowing the developer to avoid throwing exceptions throughout the system. It allows errors and messages to be accumulated throughout the process flow, enabling a cohesive response mechanism.

DevSource.Stack.Notifications is an integral part of the DevSource ecosystem.

Features

  • Validation Rules: Customizable rules for validating strings, emails, passwords, and more, ensuring data integrity and consistency across your application.
  • Notification Handling: Centralized management of notifications, providing a seamless way to collect and respond to errors and messages.
  • Test Suites: Included test suites for email validation, ensuring the robustness and reliability of your email-related operations.

Getting Started

To integrate this library into your project:

1- Setup: Include the library files in your project directory by installing directly from the NuGet repository.

    dotnet add package DevSource.Stack.Notifications

2- Initialization: Instantiate the Notifier and integrate it with your project's flow. Example:

    using DevSource.Stack.Notifications;

    public class User : Notifier
    {...}

3- Usage: Utilize the provided utilities and validations to manage errors and notifications throughout your application.

using DevSource.Stack.Notifications;
using DevSource.Stack.Notifications.Validations;

public class User() : Notifier
{
    public string Name { get; set; } = null!;
    public string Email { get; set; } = null!;
    public string Password { get; set; } = null!;

    public User(string name, string email, string password) : this()
    {
        Name = name;
        Email = email;
        Password = password;
    }

    public Task<bool> Create()
    {
        ValidationFields();

        if(HasNotifications) //Checking for notifications
            return Task.FromResult(false);

        //Here comes the logic to create user
            
        return Task.FromResult(true);
    }

    private void ValidationFields()
    {
        AddNotifications(new ValidationRules<User>()
            .IsEmail(nameof(Email), Email)
            .IsPassword(nameof(Password), Password, 8)
        );
                
    }
}

4- Capturing the notifications: To capture the notifications, you can check the Notifications property. Example:

using DevSourceNotifications;

var user = new User("John Doe", "email", "yourpassword");

var result = await user.Create();

if(result)
    Console.WriteLine("User created");
else
{
    foreach(var notification in user.Notifications)
    {
        Console.WriteLine(notification.Message);
    }
}

Result

dotnet run

The 'email' is not a valid email
The value of field 'yourpassword' is invalid

If you prefer an approach that throws Exceptions, you can follow the same logic. Just use ValidationRulesException:

public void Validate()
{
     PublishException(new ValidationRulesException<User>()
         .IsNotNullOrEmpty(nameof(Name), Name)
         .IsEmail(nameof(Email), Email)
         .IsPassword(nameof(Password), Password, 8)
     );
 }

Running the tests

To run the tests, run the following command

  dotnet test
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
2.0.0 150 6/17/2025
1.0.10 207 4/9/2025
1.0.9 159 11/29/2024
1.0.8 152 9/16/2024
1.0.6 124 9/10/2024
1.0.5 120 9/10/2024
1.0.4 122 9/1/2024
1.0.3 156 9/1/2024
1.0.2 108 8/3/2024
1.0.1 106 7/29/2024
1.0.0 111 7/25/2024