WeNerds.Services 1.0.10

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

WeNerds Services

Open-source Commons Services developed to facilitate the creation of a new project in .Net, providing some commons services.

Something is missing? Submit a new product feature request using the issues tracker..

✨ Using the library

👉 Step 1 - Install library into project

  • Package Manager
$ Install-Package WeNerds.Services
  • .Net CLI
$ dotnet add package WeNerds.Services

👉 Step 2 - Register Service<br> In the topics of each service available in the package, how to register will be explained.

✨ Services availables on the library

WeJwtService

This service provides methods for JWT manipulation.

  • GenarateJwt: Generate a JWT Token. You can specify, a TenantId, a AccountId, a UserId, a UserEmail and custom claims. WeNotificationService
  • Service for Notification Pattern

WeBabel

This service is a helper for internationalization. It provides methods to get the translation of a key in a specific language.

Configuration:

To configure the service, we can create some environment variables (or add them to AppSettings)

  • WN_BABEL_LIST_LANGUAGES
    • List of languages ​​supported by your application.
      Important: You must separate each language with a comma.
      Example: "WN_BABEL_LIST_LANGUAGES": "en,pt-BR"
  • WN_BABEL_RESOURCES_PATH
    • Path where the Json created with the dictionary to be used will be located.
      Suggestion: Create a folder called Resources in the project root and use this folder to create the Json files.
      Example: "WN_BABEL_RESOURCES_PATH": "Resources"
  • WN_BABEL_DEFAULT_LANGUAGE
    • What is the default language of the application.
      Example "WN_BABEL_DEFAULT_LANGUAGE": "pt-BR"
  • WN_BABEL_RESOURCE_NAME
    • Base name of the Json file. Just the base name of the files, it is not necessary to include the language or the extension.
      Example: Assuming that we will have 2 languages ​​pt-BR and en, two files will be created in the Resources folder: AppMessages.pt-BR.json and AppMessages.en.json.
      In this case our variable will have the value of: AppMessages.
      "WN_BABEL_RESOURCE_NAME": "AppMessages"
  • WN_BABEL_DEFAULT_CONTEXT
    • The WeBabel service supports separation of dictionaries by context. This means that you can create smaller dictionaries, so that when using the service it is not necessary to load a large number of items.
      In this variable we will then inform the default context of the application.
      Example: "WN_BABEL_DEFAULT_CONTEXT": "main"

To read environment variables, there are 5 extension methods for IConfiguration:

  • GetWeBabelResourcesPath
  • GetWeBabelResourceName
  • GetWeBabelListLanguages
  • GetWeBabelDefaultLanguage
  • GetWeBabelDefaultContext
Registering:

After creating the variables, you have to register the service.
For this there is an extension method for the IServiceCollecion called AddWeBabel, so just call the method and pass the IConfiguration as a parameter and the service is already registered and ready to use.
Example of registering a WorkerService:

IHost host = Host.CreateDefaultBuilder(args)
 .ConfigureServices(services =>
 {
     services.AddWeBabel(config); 
     services.AddHostedService<Worker>();
 })
 .Build();

Important: By default, the service is registered as Transient, but if you are not using contexts, the service can be registered as Scoped or Singleton, so simply pass the desired ServiceLifetime. Example:

IHost host = Host.CreateDefaultBuilder(args)
 .ConfigureServices(services =>
 {
    services.AddWeBabel(config, ServiceLifetime.Singleton);
    services.AddHostedService<Worker>();
 })
 .Build();
Using:

Now with the registration done, we can inject WeBabel wherever we want to use the service.
In the constructor where we are going to use the service, we do the injection

private readonly IWeBabel _babel;
public Worker(IWeBabel babel)
{
       _babel = babel.SetContext("account");
}

Note that there is a private variable that will receive the injected object.
And it is also in the constructor that we will use the Setcontext method to change the context, if used.

Json key we are looking for. Below we have an example of a command to write something to the application console:

Console.WriteLine(_babel["blocked"]);

I'm using pt-BR as the default language, so we should have the following result in our console:

Conta bloqueada

Json files examples:

AppMessages.pt-BR.json: In this example, context is not being used. Therefore, when using WeBabel, all keys and their values ​​will be loaded.

{
  "blocked": "Conta bloqueada",
  "unblocked": "Conta desbloqueada"
}

AppMessages.en.json: In this example, context is being used. Therefore when using WeBabel, only keys and values ​​within the specified context will be loaded.

{
  "account": {
      "blocked": "Account blocked",
      "notFound": "Account not found"
  },
  "person": {
      "blocked": "Peson blocked",
      "notFound": "Person not found"
  }
}

👉 Complete Documentation WIP

✨ Contacts

📧 Email - leo.cavalheiro.ti@gmail.com

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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on WeNerds.Services:

Package Downloads
WeNerds.Middlewares

Commons Middlewares

WeNerds.Filters

Commons Filtes

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.10 238 1/5/2025
1.0.9 216 1/5/2025
1.0.8 220 1/5/2025
1.0.7 201 7/31/2024
1.0.6 255 7/19/2024
1.0.5 244 7/5/2024
1.0.4 233 7/4/2024
1.0.3 239 7/1/2024
1.0.2 237 6/28/2024
1.0.1 308 6/26/2024
1.0.0 228 6/25/2024
0.1.0 204 9/16/2023