Notie 2.2.1

dotnet add package Notie --version 2.2.1
NuGet\Install-Package Notie -Version 2.2.1
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="Notie" Version="2.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Notie --version 2.2.1
#r "nuget: Notie, 2.2.1"
#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.
// Install Notie as a Cake Addin
#addin nuget:?package=Notie&version=2.2.1

// Install Notie as a Cake Tool
#tool nuget:?package=Notie&version=2.2.1

<p align="center"> <img alt="Notie" title="Notie" src=".github/assets/logo.png" width="400px" /> </p> <h3 align="center"> Notificações de maneira simples no .NET </h3>

<p align="center">

<a href="https://dotnet.microsoft.com/"> <img alt="GitHub language count" src="https://img.shields.io/badge/language-1-blue"> </a>

<a href="https://github.com/iuryferreira/"> <img alt="Made by Iury Ferreira" src="https://img.shields.io/badge/made%20by-Iury%20Ferreira-blue"> </a>

<a href="https://nuget.org/packages/Notie"> <img alt="Version" src="https://img.shields.io/nuget/v/notie"> </a>

<a href="https://nuget.org/packages/Notie"> <img alt="Downloads" src="https://img.shields.io/nuget/dt/notie"> </a>

<a href='https://coveralls.io/github/iuryferreira/notie?branch=main'> <img src='https://coveralls.io/repos/github/iuryferreira/notie/badge.svg?branch=main' alt='Coverage Status'/> </a>

<a href="hhttps://github.com/iuryferreira/notie/actions/workflows/publish.yaml"> <img alt="Version" src="https://github.com/iuryferreira/notie/actions/workflows/publish.yaml/badge.svg?branch=main"> </a>

</p>

<p align="center" style="font-size:10px">Don't know portuguese? check the documentation in english <a href="docs/en-us.md">here</a>.</p>

✌ Olá!

Notie é uma maneira simples de implementar o Notification Pattern para agrupar suas validações. A diferença é que ele é multifuncional, então você pode usá-lo para notificações em qualquer classe ou camada que desejar. Faça o que você quiser! 😄

Ele contém uma classe Notifier que é responsável por gerenciar as notificações do tipo Notification.

🛠 Instalação

Use os meios de instalação abaixo.

CLI (Linux/Windows/Mac)

Para instalar pela linha de comando (CLI), basta executar o seguinte comando na pasta do seu projeto:

  dotnet add package Notie
Gerenciador de pacotes NuGet (Windows/Mac/Linux)

Basta pesquisar por "Notie" em seu Visual Studio/Rider e clicar em adicionar pacote.

💻 Funcionamento

Notie é intuitivo e você pode usar a documentação fornecida pelo código para ajudá-lo, mas também deixarei exemplos aqui.

AddNotification

O AddNotification recebe um objeto Notification que contém uma chave e valor, que poderia ser o campo e a mensagem que deseja informar.

using Notie;

// your validation here...

var notification = new Notification("any_key", "any_message");
INotifier notifier = new Notifier();

notifier.AddNotification(notification);

if (notifier.HasNotifications())
{
  // Handle...
}

No caso acima, você cria um objeto da classe Notification e adiciona ao seu Notifier.

AddNotifications

Você pode receber uma lista de notificações por meio do método AddNotifications. Se já existirem notificações no Notifier, elas serão mescladas por padrão. Consultar exemplo:

using Notie;

// your validation here...

List<Notification> notifications = new()
{
  new("any_key", "any_message"),
  new("other_key", "other_message")
};

INotifier notifier = new Notifier();

notifier.AddNotifications(notifications);

if (notifier.HasNotifications())
{
  // Handle...
}

Se você quiser sobrescrever as notificações anteriores, apenas defina o parâmetro overwrite como true, conforme mostrado abaixo.

// ...

notifier.AddNotifications(notifications, overwrite: true);

if (notifier.HasNotifications())
{
  // Handle...
}

AddNotificationsByFluent

O Notie tem suporte ao FluentValidation. Se você o utiliza para realizar as validações, você pode integrá-las através do método AddNotificationsByFluent, passando um ValidationResult.

using Notie;

Entity entity = new Entity();
EntityValidator validator = new EntityValidator();
ValidationResult result = validator.Validate(entity);

INotifier notifier = new Notifier();
notifier.AddNotificationsByFluent(result);

if (notifier.HasNotifications())
{
  // Handle...
}

Se você quiser sobrescrever as notificações anteriores, apenas defina o parâmetro overwrite como true, conforme mostrado abaixo.

// ...

notifier.AddNotificationsByFluent(notifications, overwrite: true);

if (notifier.HasNotifications())
{
  // Handle...
}

All

Para listar todas as notificações contidas no Notifier basta chamar o método All, como mostra o exemplo abaixo:

using Notie;

INotifier notifier = new Notifier();

// ...

notifier.All()

HasNotifications

Para verificar se existem notificações no Notifier basta chamar o método HasNotifications, como mostra o exemplo abaixo:

using Notie;

INotifier notifier = new Notifier();

// ...

bool exists = notifier.HasNotifications()

GetByKey

Se você deseja obter notificações baseadas nas chaves, poderá utilizar o método GetByKey. Você fornece o nome da chave e recebe uma lista das notificações que contém a chave informada, como no exemplo abaixo:

using Notie;

INotifier notifier = new Notifier();

// ...

var notifications = notifier.GetByKey("any_key")

GetByMessage

Se você deseja obter notificações baseadas nas mensagens, poderá utilizar o método GetByMessage. Você fornece uma mensagem e recebe uma lista das notificações que contém a mensagem informada, como no exemplo abaixo:

using Notie;

INotifier notifier = new Notifier();

// ...

var notifications = notifier.GetByMessage("any_message")

GetBy

Você também pode passar uma expressão para o método GetBy. Assim você pode verificar através da mensagem e da chave, caso preferir.

using Notie;

INotifier notifier = new Notifier();

// ...

var notifications = notifier.GetBy(x => x.Key == "any_key" && x.Message == "any_message")

Any

O método Any é responsável por verificar se existe uma notificação baseado na expressão informada.

using Notie;

INotifier notifier = new Notifier();

// ...

bool exists = notifier.Any(x => x.Key == "any_key" && x.Message == "any_message")

Clear

Se você deseja limpar todas as notificações, pode fazê-lo usando o método Clear.

using Notie;

INotifier notifier = new Notifier();

// ...

notifier.Clear()

ℹ Injeção de Dependência

Se você deseja utilizar com ASP.NET ou consumir via construtor, você pode adicionar a sua coleção de serviços IServiceCollection. Basta inserir no seu arquivo Statup.cs no método ConfigureServices a seguinte chamada:

using Notie;

// ...

public void ConfigureServices (IServiceCollection services)
{
  services.AddNotie();
}

// ...

📢 Observações

Essa documentação será incrementada conforme o projeto avança. Caso tenha dúvidas contate-me ou abra uma issue, a qual responderei o mais rápido possível. Fico feliz com seu comentário. 😄

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 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. 
.NET Framework net47 is compatible.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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
2.2.1 173 12/30/2023
2.2.0 92 12/30/2023
2.1.0 387 9/23/2021
2.0.2 336 8/25/2021
2.0.1 364 8/19/2021
2.0.0 353 7/18/2021
1.0.2 491 3/27/2021