diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index f18640fa..972af332 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -2,9 +2,9 @@ name: Build test and pack on: push: - branches: [main, develop] + branches: [master, develop] pull_request: - branches: [main, develop] + branches: [master, develop] jobs: build: @@ -18,7 +18,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Restore dependencies run: dotnet restore diff --git a/.github/workflows/dockerhub-publish.yml b/.github/workflows/dockerhub-publish.yml index e8d987f2..f0883407 100644 --- a/.github/workflows/dockerhub-publish.yml +++ b/.github/workflows/dockerhub-publish.yml @@ -30,7 +30,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Restore dependencies run: dotnet restore diff --git a/.github/workflows/nuget-publish.yml b/.github/workflows/nuget-publish.yml index 7e70f358..160a6a54 100644 --- a/.github/workflows/nuget-publish.yml +++ b/.github/workflows/nuget-publish.yml @@ -13,7 +13,7 @@ on: description: "Packages Version" # Default value if no value is explicitly provided - default: "6.2.0" + default: "7.0.0" # Input has to be provided for the workflow to run required: true @@ -30,7 +30,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Restore dependencies run: dotnet restore diff --git a/.gitignore b/.gitignore index 65f178a7..80a047aa 100644 --- a/.gitignore +++ b/.gitignore @@ -10,11 +10,6 @@ *.userosscache *.sln.docstates -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* # Build results [Dd]ebug/ @@ -255,8 +250,6 @@ orleans.codegen.cs # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) #bower_components/ -# RIA/Silverlight projects -Generated_Code/ # Backup & report files from converting an old project file # to a newer Visual Studio version. Backup files are not needed, @@ -301,13 +294,6 @@ node_modules/ # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) *.vbw -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions # Paket dependency manager .paket/paket.exe @@ -316,15 +302,6 @@ paket-files/ # FAKE - F# Make .fake/ -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# CodeRush personal settings -.cr/personal # Python Tools for Visual Studio (PTVS) __pycache__/ @@ -337,14 +314,9 @@ __pycache__/ # Tabs Studio *.tss -# Telerik's JustMock configuration file -*.jmconfig -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs + + # OpenCover UI analysis results OpenCover/ @@ -358,8 +330,6 @@ ASALocalRun/ # NVidia Nsight GPU debugger configuration file *.nvuser -# MFractors (Xamarin productivity tool) working folder -.mfractor/ logs/ @@ -466,3 +436,5 @@ $RECYCLE.BIN/ !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json + +## *.env \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c87ede3..6bb4f649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +### [v7.0.0](https://github.com/Genocs/genocs-library/compare/v6.4.0...v7.0.0) + +> 24 November 2024 + +- Ver 700 [`#120`](https://github.com/Genocs/genocs-library/pull/120) +- Merge to master branch [`#114`](https://github.com/Genocs/genocs-library/pull/114) +- Ver 640 [`#109`](https://github.com/Genocs/genocs-library/pull/109) +- Ver 600 [`#106`](https://github.com/Genocs/genocs-library/pull/106) +- v6.2.0 [`#100`](https://github.com/Genocs/genocs-library/pull/100) +- Ver 610 [`#98`](https://github.com/Genocs/genocs-library/pull/98) +- Ver 600 [`#89`](https://github.com/Genocs/genocs-library/pull/89) +- Ver 600 [`#86`](https://github.com/Genocs/genocs-library/pull/86) +- Update LangVersion, target frameworks, and refactor code [`10f3fc8`](https://github.com/Genocs/genocs-library/commit/10f3fc8ce182cc062a4cbbe3b3a38964d05cd1b4) +- Update Genocs.Core and related package references to version 7.0.0 [`6a1f7e0`](https://github.com/Genocs/genocs-library/commit/6a1f7e0d896088b91dd20220ae01e7081f78b988) +- Refactor Docker configurations and update README for improved setup instructions [`f73d401`](https://github.com/Genocs/genocs-library/commit/f73d401c6c323ba7aa92675e8929c8811d53730c) +- Update LangVersion, packages, and target frameworks [`af78d8d`](https://github.com/Genocs/genocs-library/commit/af78d8d8b790a53a9a73296b1118bdc96cf6721d) +- Update CHANGELOG for v6.4.0 release with recent changes and improvements [`74a96fd`](https://github.com/Genocs/genocs-library/commit/74a96fd04d8a263e3087e91e8c34e2a5d9e6b5f0) +- Update GitHub workflows and documentation for .NET 9 support [`307877e`](https://github.com/Genocs/genocs-library/commit/307877e76d1eb89ec646a5883cea52b305272bbf) +- Update package versions and remove unused import [`766bec0`](https://github.com/Genocs/genocs-library/commit/766bec0cfe96a169280fe198ceed6c8917b59df3) + #### [v6.4.0](https://github.com/Genocs/genocs-library/compare/v6.3.0...v6.4.0) > 10 November 2024 diff --git a/Directory.Build.props b/Directory.Build.props index 49772f3a..ae739882 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,7 +14,7 @@ True True 6.3.0 - 10.0 + 13.0 Genocs Genocs 2024 LICENSE diff --git a/README.md b/README.md index 5faf79c1..e493e8c7 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ # Genocs .NET library -This repo contains a set of libraries to build LOB (Line Of Business) applications. The library is open source and built to be PRODUCTION READY. The library is built on top of .NET8, it is designed and maintained by Genocs. +This repo contains a set of libraries to build LOB (Line Of Business) applications. The library is open source and built to be PRODUCTION READY. The library is built on top of .NET9, it is designed and maintained by Genocs. Packages are available on [NuGet Genocs](https://www.nuget.org/profiles/gioema_nocco). @@ -74,9 +74,18 @@ You can use **Docker compose** to setup the infrastructure components just by ru ``` bash cd ./containers # Setup the infrastructure -docker compose -f ./infrastructure-bare.yml --env-file ./.env --project-name genocs up -d +docker compose -f ./infrastructure.yml --env-file ./.env --project-name genocs up -d + +# Use this file only in case you want to setup Redis and Postgres db (no need if you use mongo) +docker compose -f ./infrastructure-db.yml --env-file ./.env --project-name genocs up -d + +# Use this file only in case you want to setup monitoring infrastructure components (Prometheus, Grafana, InfluxDB, Jaeger, Seq) docker compose -f ./infrastructure-monitoring.yml --env-file ./.env --project-name genocs up -d + +# Use this file only in case you want to setup scaling infrastructure components (Fabio, Consul) docker compose -f ./infrastructure-scaling.yml --env-file ./.env --project-name genocs up -d + +# Use this file only in case you want to setup security infrastructure components (Vault) docker compose -f ./infrastructure-security.yml --env-file ./.env --project-name genocs up -d # Use this file only in case you want to setup sqlserver database (no need if you use postgres) diff --git a/containers/.env b/containers/.env deleted file mode 100644 index e69de29b..00000000 diff --git a/containers/infrastructure-db.yml b/containers/infrastructure-db.yml new file mode 100644 index 00000000..0aac2ef3 --- /dev/null +++ b/containers/infrastructure-db.yml @@ -0,0 +1,39 @@ +services: + + redis: + image: redis + hostname: redis + container_name: redis + ports: + - 6379:6379 + networks: + - genocs + # network_mode: host + volumes: + - redis:/data + + postgres: + image: postgres + hostname: postgres + container_name: postgres + environment: + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + ports: + - 5432:5432 + networks: + - genocs + # network_mode: host + volumes: + - postgres:/var/lib/postgresql/data + +networks: + genocs: + name: genocs-network + driver: bridge + external: true + +volumes: + redis: + driver: local + postgres: + driver: local \ No newline at end of file diff --git a/containers/infrastructure-bare.yml b/containers/infrastructure.yml similarity index 54% rename from containers/infrastructure-bare.yml rename to containers/infrastructure.yml index 31e236da..b13dfbc9 100644 --- a/containers/infrastructure-bare.yml +++ b/containers/infrastructure.yml @@ -25,32 +25,6 @@ services: volumes: - mongodb:/data/db - redis: - image: redis - hostname: redis - container_name: redis - ports: - - 6379:6379 - networks: - - genocs - # network_mode: host - volumes: - - redis:/data - - postgres: - image: postgres - hostname: postgres - container_name: postgres - environment: - - POSTGRES_PASSWORD=mysecretpassword - ports: - - 5432:5432 - networks: - - genocs - # network_mode: host - volumes: - - postgres:/var/lib/postgresql/data - networks: genocs: name: genocs-network @@ -61,7 +35,3 @@ volumes: driver: local rabbitmq: driver: local - redis: - driver: local - postgres: - driver: local \ No newline at end of file diff --git a/containers/local.env b/containers/local.env new file mode 100644 index 00000000..d600fa89 --- /dev/null +++ b/containers/local.env @@ -0,0 +1,2 @@ +# This file is a template for the .env file that is used by the docker-compose.yml file. +POSTGRES_PASSWORD=<> diff --git a/local.env b/local.env index e69de29b..14349d0a 100644 --- a/local.env +++ b/local.env @@ -0,0 +1,10 @@ +# Compose supports declaring default environment variables in an environment file named .env placed in the folder docker-compose command is executed from (current working directory). +# Compose expects each line in an env file to be in VAR=VAL format. Lines beginning with # (i.e. comments) are ignored, as are blank lines. +# Note: Values present in the environment at runtime will always override those defined inside the .env file. Similarly, values passed via command-line arguments take precedence as well. + +# The IP below should be swapped to your real IP or DNS name, like 192.168.88.248, etc. if testing from remote browsers or mobile devices + +PROJECT_EXTERNAL_DNS_NAME_OR_IP=localhost + +# The docker image version +DOCKER_IMAGE_TAG=6.0.0 diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 00000000..10099e73 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,44 @@ +# Description + +This folder contains useful script you can use to automate tasks. The scripts are bash or powershell scripts. + +## How to obtain the list of repository on Azure DevOps + +[Repository List](https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/list?view=azure-devops-rest-5.0) + +```api +https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/list?view=azure-devops-rest-5.0 +https://dev.azure.com/genocs/_apis/git/repositories?api-version=5.0 +``` +### List of repositories + + + + +### Window Services + +Following some commands that you can use to handle windows services + +``` cmd +echo To query the available windows services +sc query + +echo To remove the registration +SC DELETE [service_name] +``` + + +## How to clone the repositories at once + +1. Open a bash shell +2. Run the following command + +```bash +./git-clone-all.sh +``` + +3. Checkout develop branch + +```bash +./git-pull-all.sh +``` diff --git a/scripts/git-clone-all.sh b/scripts/git-clone-all.sh new file mode 100644 index 00000000..5f11b236 --- /dev/null +++ b/scripts/git-clone-all.sh @@ -0,0 +1,16 @@ +#!/bin/bash +REPOSITORIES=(genocs-library) + +if [ "$1" = "-p" ] + then + echo ${REPOSITORIES[@]} | sed -E -e 's/[[:blank:]]+/\n/g' | xargs -I {} -n 1 -P 0 sh -c 'printf "========================================================\nCloning repository: {}\n========================================================\n"; git clone https://github.com/Genocs/_git/{}' + else + for REPOSITORY in ${REPOSITORIES[*]} + do + echo ======================================================== + echo Cloning repository: $REPOSITORY + echo ======================================================== + REPO_URL=https://github.com/Genocs/_git/$REPOSITORY + git clone $REPO_URL + done +fi \ No newline at end of file diff --git a/scripts/git-pull-all.sh b/scripts/git-pull-all.sh new file mode 100644 index 00000000..acb2cedd --- /dev/null +++ b/scripts/git-pull-all.sh @@ -0,0 +1,27 @@ +#!/bin/bash +REPOSITORIES=(genocs-library) + +if [ "$1" = "-p" ] + then + echo ${REPOSITORIES[@]} | sed -E -e 's/[[:blank:]]+/\n/g' | xargs -I {} -n 1 -P 0 sh -c 'printf "========================================================\nUpdating repository: {}\n========================================================\n"; git -C {} pull; git -C {} checkout develop; ' + else + for REPOSITORY in ${REPOSITORIES[*]} + do + echo ======================================================== + echo Updating repository: $REPOSITORY + echo ======================================================== + cd $REPOSITORY + git pull + #git checkout master + #git checkout develop + #echo 'clear local branches' + #git remote prune origin --dry-run + #git remote update origin --p + echo 'number of branches' + #echo 'remote:' + git branch -r | wc -l + #echo 'all:' + #git branch --all | wc -l + cd .. + done +fi \ No newline at end of file diff --git a/scripts/git-push-andcommit-all.sh b/scripts/git-push-andcommit-all.sh new file mode 100644 index 00000000..3b059a5c --- /dev/null +++ b/scripts/git-push-andcommit-all.sh @@ -0,0 +1,19 @@ +#!/bin/bash +REPOSITORIES=(genocs-library) + +if [ "$1" = "-p" ] + then + echo ${REPOSITORIES[@]} | sed -E -e 's/[[:blank:]]+/\n/g' | xargs -I {} -n 1 -P 0 sh -c 'printf "========================================================\nPush and commit repository: {}\n========================================================\n"; git add .; git commit -a -m "Updated Packages";git push;' + else + for REPOSITORY in ${REPOSITORIES[*]} + do + echo ======================================================== + echo Add new files, Commit changes and Push on repository: $REPOSITORY + echo ======================================================== + cd $REPOSITORY + git add . + git commit -a -m "Automatic commit" + git push + cd .. + done +fi \ No newline at end of file diff --git a/src/Genocs.Auth/Genocs.Auth.csproj b/src/Genocs.Auth/Genocs.Auth.csproj index 924792ef..20296ed5 100644 --- a/src/Genocs.Auth/Genocs.Auth.csproj +++ b/src/Genocs.Auth/Genocs.Auth.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Auth Genocs.Auth Genocs.Auth @@ -24,10 +24,15 @@ - - + + + + + + + diff --git a/src/Genocs.Auth/README_NUGET.md b/src/Genocs.Auth/README_NUGET.md index 86096c0e..893e23ec 100644 --- a/src/Genocs.Auth/README_NUGET.md +++ b/src/Genocs.Auth/README_NUGET.md @@ -3,7 +3,7 @@ This package contains a set of functionalities to handling authorization logic as JWT. First of all I have to say thanks to devmentors. -The libraries are built using net8, net7, net6. +The libraries are built using .NET9, .NET8, .NET7, .NET6. ## Description diff --git a/src/Genocs.Common/Genocs.Common.csproj b/src/Genocs.Common/Genocs.Common.csproj index 2ade0ec7..5190a096 100644 --- a/src/Genocs.Common/Genocs.Common.csproj +++ b/src/Genocs.Common/Genocs.Common.csproj @@ -1,13 +1,13 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Common Genocs.Common Genocs.Common The Genocs Library - Common components. The common components to build .NET Core projects along with Genocs Library. - true + true 5.0.0 Nocco Giovanni Emanuele microservice microservices solid solid-principles genocs diff --git a/src/Genocs.Core.Demo.Contracts/Genocs.Core.Demo.Contracts.csproj b/src/Genocs.Core.Demo.Contracts/Genocs.Core.Demo.Contracts.csproj index 69c454cc..0e849290 100644 --- a/src/Genocs.Core.Demo.Contracts/Genocs.Core.Demo.Contracts.csproj +++ b/src/Genocs.Core.Demo.Contracts/Genocs.Core.Demo.Contracts.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 false false @@ -11,7 +11,7 @@ - + diff --git a/src/Genocs.Core.Demo.Domain/Genocs.Core.Demo.Domain.csproj b/src/Genocs.Core.Demo.Domain/Genocs.Core.Demo.Domain.csproj index 39f3fc59..2f1181c7 100644 --- a/src/Genocs.Core.Demo.Domain/Genocs.Core.Demo.Domain.csproj +++ b/src/Genocs.Core.Demo.Domain/Genocs.Core.Demo.Domain.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 false false @@ -12,8 +12,8 @@ - - + + diff --git a/src/Genocs.Core.Demo.Infrastructure/Genocs.Core.Demo.Infrastructure.csproj b/src/Genocs.Core.Demo.Infrastructure/Genocs.Core.Demo.Infrastructure.csproj index dc1d6876..657c487a 100644 --- a/src/Genocs.Core.Demo.Infrastructure/Genocs.Core.Demo.Infrastructure.csproj +++ b/src/Genocs.Core.Demo.Infrastructure/Genocs.Core.Demo.Infrastructure.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 false false diff --git a/src/Genocs.Core.Demo.WebApi/Controllers/HomeController.cs b/src/Genocs.Core.Demo.WebApi/Controllers/HomeController.cs index d9a29280..ae65a0d2 100644 --- a/src/Genocs.Core.Demo.WebApi/Controllers/HomeController.cs +++ b/src/Genocs.Core.Demo.WebApi/Controllers/HomeController.cs @@ -14,16 +14,6 @@ public HomeController(SecretOptions secretSettings) _secretSettings = secretSettings ?? throw new ArgumentNullException(nameof(secretSettings)); } - [HttpGet] - [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] - public IActionResult Get() - => Ok("Genocs Demo WebApi"); - - [HttpGet("ping")] - [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] - public IActionResult Ping() - => Ok("pong"); - [HttpGet("secret")] [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] public IActionResult GetSecret() diff --git a/src/Genocs.Core.Demo.WebApi/Genocs.Core.Demo.WebApi.csproj b/src/Genocs.Core.Demo.WebApi/Genocs.Core.Demo.WebApi.csproj index 8b857be6..2e1f5546 100644 --- a/src/Genocs.Core.Demo.WebApi/Genocs.Core.Demo.WebApi.csproj +++ b/src/Genocs.Core.Demo.WebApi/Genocs.Core.Demo.WebApi.csproj @@ -1,12 +1,10 @@  - net8.0 + net9.0 false false - genocs - Linux - ..\.. + Genocs @@ -22,19 +20,21 @@ - - - - - - - - - + + + + + + + + + - + + + diff --git a/src/Genocs.Core.Demo.WebApi/Program.cs b/src/Genocs.Core.Demo.WebApi/Program.cs index e0b37556..8b850a98 100644 --- a/src/Genocs.Core.Demo.WebApi/Program.cs +++ b/src/Genocs.Core.Demo.WebApi/Program.cs @@ -39,8 +39,6 @@ x.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); -services.AddHealthChecks(); - services.Configure(builder.Configuration.GetSection(SecretOptions.Position)); SecretOptions settings = builder.Configuration.GetOptions(SecretOptions.Position); @@ -86,9 +84,9 @@ // Use it only if you need to authenticate with Firebase // app.UseFirebaseAuthentication(); -app.MapControllers(); +app.MapDefaultEndpoints(); -app.MapHealthChecks("/hc"); +app.MapControllers(); app.Run(); diff --git a/src/Genocs.Core.Demo.WebApi/appsettings.json b/src/Genocs.Core.Demo.WebApi/appsettings.json index 34a70d64..9a13704a 100644 --- a/src/Genocs.Core.Demo.WebApi/appsettings.json +++ b/src/Genocs.Core.Demo.WebApi/appsettings.json @@ -10,7 +10,7 @@ "logger": { "level": "debug", "applicationName": "demo-service", - "excludePaths": [ "/ping", "/metrics" ], + "excludePaths": [ "/health", "/alive" ], "console": { "enabled": true }, diff --git a/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj b/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj index f3eef8fe..a726e6f8 100644 --- a/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj +++ b/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj @@ -1,12 +1,10 @@  - net8.0 + net9.0 false false - __genocs - Linux - ..\.. + _Genocs @@ -16,15 +14,16 @@ - - - + + + - + + diff --git a/src/Genocs.Core.UnitTests/Genocs.Core.UnitTests.csproj b/src/Genocs.Core.UnitTests/Genocs.Core.UnitTests.csproj index 99505860..418db733 100644 --- a/src/Genocs.Core.UnitTests/Genocs.Core.UnitTests.csproj +++ b/src/Genocs.Core.UnitTests/Genocs.Core.UnitTests.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 false false diff --git a/src/Genocs.Core/Builders/Extensions.cs b/src/Genocs.Core/Builders/Extensions.cs index 72fa6c39..c389cd7e 100644 --- a/src/Genocs.Core/Builders/Extensions.cs +++ b/src/Genocs.Core/Builders/Extensions.cs @@ -1,8 +1,13 @@ +using System.Reflection; using Genocs.Common.Configurations; using Genocs.Common.Types; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Hosting; namespace Genocs.Core.Builders; @@ -11,6 +16,13 @@ namespace Genocs.Core.Builders; /// public static class Extensions { + public static IGenocsBuilder AddGenocs(this WebApplicationBuilder builder) + { + // Create the builder + IGenocsBuilder gnxBuilder = GenocsBuilder.Create(builder); + return gnxBuilder; + } + /// /// The Builder. /// @@ -19,12 +31,22 @@ public static class Extensions /// The builder. public static IGenocsBuilder AddGenocs(this IServiceCollection services, IConfiguration? configuration = null) { - var builder = GenocsBuilder.Create(services, configuration); - var settings = builder.GetOptions(AppOptions.Position); - services.AddSingleton(settings); + // Create the builder + IGenocsBuilder builder = GenocsBuilder.Create(services, configuration); + + // Get the application options + AppOptions settings = builder.GetOptions(AppOptions.Position); + builder.Services.AddSingleton(settings); + + // Add the health checks + builder.Services + .AddHealthChecks() + .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); // Add a default liveness check to ensure app is responsive builder.Services.AddMemoryCache(); - services.AddSingleton(); + + builder.Services.AddSingleton(); + if (!settings.DisplayBanner || string.IsNullOrWhiteSpace(settings.Name)) { return builder; @@ -87,4 +109,77 @@ public static TModel GetOptions(this IGenocsBuilder builder, string sect var configuration = serviceProvider.GetRequiredService(); return configuration.GetOptions(sectionName); } + + /// + /// Map default endpoints to setup health checks. + /// + /// The web Application. + /// The WebApplication to be used for chain. + public static IApplicationBuilder MapDefaultEndpoints(this IApplicationBuilder app) + { + // Adding health checks endpoints to applications in non-development environments has security implications. + // See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments. + + app.UseEndpoints(endpoints => + { + endpoints.MapGet("/", async context => + { + // Get the Entry Assembly Name and Version + // Check performance implications of calling this method + string? assemblyVersion = Assembly.GetEntryAssembly()?.GetCustomAttribute()?.InformationalVersion; + string? serviceVersion = context.RequestServices.GetService()?.Name; + string message = $"Service {serviceVersion ?? assemblyVersion} is running"; + + await context.Response.WriteAsync(context.RequestServices.GetService()?.Name ?? "Service"); + }); + + // All health checks must pass for app to be considered ready to accept traffic after starting + endpoints.MapHealthChecks("/health"); + + // Only health checks tagged with the "live" tag must pass for app to be considered alive + endpoints.MapHealthChecks("/alive", new HealthCheckOptions + { + Predicate = r => r.Tags.Contains("live") + }); + }); + + return app; + } + + /// + /// Map default endpoints to setup health checks. + /// + /// The web Application. + /// The WebApplication to be used for chain. + public static WebApplication MapDefaultEndpoints(this WebApplication app) + { + // Adding health checks endpoints to applications in non-development environments has security implications. + // See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments. + if (!app.Environment.IsDevelopment()) + { + return app; + } + + app.MapGet("/", async context => + { + // Get the Entry Assembly Name and Version + // Check performance implications of calling this method + string? assemblyVersion = Assembly.GetEntryAssembly()?.GetCustomAttribute()?.InformationalVersion; + string? serviceVersion = context.RequestServices.GetService()?.Name; + string message = $"Service {serviceVersion ?? assemblyVersion} is running"; + + await context.Response.WriteAsync(context.RequestServices.GetService()?.Name ?? message); + }); + + // All health checks must pass for app to be considered ready to accept traffic after starting + app.MapHealthChecks("/health"); + + // Only health checks tagged with the "live" tag must pass for app to be considered alive + app.MapHealthChecks("/alive", new HealthCheckOptions + { + Predicate = r => r.Tags.Contains("live") + }); + + return app; + } } \ No newline at end of file diff --git a/src/Genocs.Core/Builders/GenocsBuilder.cs b/src/Genocs.Core/Builders/GenocsBuilder.cs index 59c5b25b..8be14b99 100644 --- a/src/Genocs.Core/Builders/GenocsBuilder.cs +++ b/src/Genocs.Core/Builders/GenocsBuilder.cs @@ -1,7 +1,8 @@ +using System.Collections.Concurrent; using Genocs.Common.Types; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using System.Collections.Concurrent; namespace Genocs.Core.Builders; @@ -18,16 +19,32 @@ public sealed class GenocsBuilder : IGenocsBuilder /// /// The configuration. /// - public IConfiguration? Configuration { get; } + public IConfiguration? Configuration { get; private set; } + + public WebApplicationBuilder? WebApplicationBuilder { get; private set; } private GenocsBuilder(IServiceCollection services, IConfiguration? configuration) { - _buildActions = new List>(); _services = services; - _services.AddSingleton(new StartupInitializer()); Configuration = configuration; + + _buildActions = new List>(); + _services.AddSingleton(new StartupInitializer()); } + private GenocsBuilder(WebApplicationBuilder builder) + { + WebApplicationBuilder = builder; + Configuration = builder.Configuration; + + _services = builder.Services; + _buildActions = new List>(); + _services.AddSingleton(new StartupInitializer()); + } + + public static IGenocsBuilder Create(WebApplicationBuilder builder) + => new GenocsBuilder(builder); + public static IGenocsBuilder Create(IServiceCollection services, IConfiguration? configuration = null) => new GenocsBuilder(services, configuration); diff --git a/src/Genocs.Core/Builders/IGenocsBuilder.cs b/src/Genocs.Core/Builders/IGenocsBuilder.cs index 5ec0b17e..ca35ed0d 100644 --- a/src/Genocs.Core/Builders/IGenocsBuilder.cs +++ b/src/Genocs.Core/Builders/IGenocsBuilder.cs @@ -1,4 +1,5 @@ using Genocs.Common.Types; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -17,7 +18,9 @@ public interface IGenocsBuilder /// /// Get the configuration. /// - IConfiguration Configuration { get; } + IConfiguration? Configuration { get; } + + WebApplicationBuilder? WebApplicationBuilder { get; } /// /// try to register a service by name. diff --git a/src/Genocs.Core/Exceptions/GenocsException.cs b/src/Genocs.Core/Exceptions/GenocsException.cs index 0c233be5..83b06d02 100644 --- a/src/Genocs.Core/Exceptions/GenocsException.cs +++ b/src/Genocs.Core/Exceptions/GenocsException.cs @@ -45,4 +45,15 @@ public GenocsException(string message, Exception? innerException) { } + + + /// + /// Creates a new object. + /// + /// + public class InvalidConfigurationException(string message) + : GenocsException(message) + { + + } } diff --git a/src/Genocs.Core/Genocs.Core.csproj b/src/Genocs.Core/Genocs.Core.csproj index 32e880bc..361e1a50 100644 --- a/src/Genocs.Core/Genocs.Core.csproj +++ b/src/Genocs.Core/Genocs.Core.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Core Genocs.Core Genocs.Core @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Discovery.Consul/Extensions.cs b/src/Genocs.Discovery.Consul/Extensions.cs index a8a8c511..6a16f2be 100644 --- a/src/Genocs.Discovery.Consul/Extensions.cs +++ b/src/Genocs.Discovery.Consul/Extensions.cs @@ -158,6 +158,6 @@ private static string ParseTime(string value) return DefaultInterval; } - return int.TryParse(value, out var number) ? $"{number}s" : value; + return int.TryParse(value, out int number) ? $"{number}s" : value; } } \ No newline at end of file diff --git a/src/Genocs.Discovery.Consul/Genocs.Discovery.Consul.csproj b/src/Genocs.Discovery.Consul/Genocs.Discovery.Consul.csproj index fc01345c..9055f004 100644 --- a/src/Genocs.Discovery.Consul/Genocs.Discovery.Consul.csproj +++ b/src/Genocs.Discovery.Consul/Genocs.Discovery.Consul.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Discovery.Consul Genocs.Discovery.Consul Genocs.Discovery.Consul @@ -24,11 +24,12 @@ - - + + - + + diff --git a/src/Genocs.HTTP.RestEase/Genocs.HTTP.RestEase.csproj b/src/Genocs.HTTP.RestEase/Genocs.HTTP.RestEase.csproj index 1110507f..a6aacfd6 100644 --- a/src/Genocs.HTTP.RestEase/Genocs.HTTP.RestEase.csproj +++ b/src/Genocs.HTTP.RestEase/Genocs.HTTP.RestEase.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.HTTP.RestEase Genocs.HTTP.RestEase Genocs.HTTP.RestEase @@ -25,13 +25,14 @@ - - - - + + + + + diff --git a/src/Genocs.HTTP/Genocs.HTTP.csproj b/src/Genocs.HTTP/Genocs.HTTP.csproj index f7aa5933..001692e7 100644 --- a/src/Genocs.HTTP/Genocs.HTTP.csproj +++ b/src/Genocs.HTTP/Genocs.HTTP.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.HTTP Genocs.HTTP Genocs.HTTP @@ -22,12 +22,12 @@ - + - - + + diff --git a/src/Genocs.LoadBalancing.Fabio/Genocs.LoadBalancing.Fabio.csproj b/src/Genocs.LoadBalancing.Fabio/Genocs.LoadBalancing.Fabio.csproj index 0f2c4d4b..d81ff3b4 100644 --- a/src/Genocs.LoadBalancing.Fabio/Genocs.LoadBalancing.Fabio.csproj +++ b/src/Genocs.LoadBalancing.Fabio/Genocs.LoadBalancing.Fabio.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.LoadBalancing.Fabio Genocs.LoadBalancing.Fabio Genocs.LoadBalancing.Fabio @@ -24,9 +24,13 @@ - - - + + + + + + + diff --git a/src/Genocs.Logging/Configurations/AzureOptions.cs b/src/Genocs.Logging/Configurations/AzureOptions.cs index dc2f326a..81af694c 100644 --- a/src/Genocs.Logging/Configurations/AzureOptions.cs +++ b/src/Genocs.Logging/Configurations/AzureOptions.cs @@ -14,4 +14,15 @@ public class AzureOptions /// The Azure application insights connection string. /// public string? ConnectionString { get; set; } + + + /// + /// It define whether the Azure application insights logger and tracing are enabled or not. + /// + public bool EnableTracing { get; set; } + + /// + /// It define whether the Azure application insights logger and metrics are enabled or not. + /// + public bool EnableMetrics { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Logging/Configurations/ConsoleOptions.cs b/src/Genocs.Logging/Configurations/ConsoleOptions.cs index 4289e516..4112f484 100644 --- a/src/Genocs.Logging/Configurations/ConsoleOptions.cs +++ b/src/Genocs.Logging/Configurations/ConsoleOptions.cs @@ -9,4 +9,14 @@ public class ConsoleOptions /// It define whether the console logger and tracing are enabled or not. /// public bool Enabled { get; set; } + + /// + /// It define whether the console logger and tracing are enabled or not. + /// + public bool EnableTracing { get; set; } + + /// + /// It define whether the console logger and metrics are enabled or not. + /// + public bool EnableMetrics { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Logging/Genocs.Logging.csproj b/src/Genocs.Logging/Genocs.Logging.csproj index 68b271d5..5412bc16 100644 --- a/src/Genocs.Logging/Genocs.Logging.csproj +++ b/src/Genocs.Logging/Genocs.Logging.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Logging Genocs.Logging Genocs.Logging @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.MessageBrokers.Outbox.MongoDB/Genocs.MessageBrokers.Outbox.MongoDB.csproj b/src/Genocs.MessageBrokers.Outbox.MongoDB/Genocs.MessageBrokers.Outbox.MongoDB.csproj index 55003bab..e06755d9 100644 --- a/src/Genocs.MessageBrokers.Outbox.MongoDB/Genocs.MessageBrokers.Outbox.MongoDB.csproj +++ b/src/Genocs.MessageBrokers.Outbox.MongoDB/Genocs.MessageBrokers.Outbox.MongoDB.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.MessageBrokers.Outbox.MongoDB Genocs.MessageBrokers.Outbox.MongoDB Genocs.MessageBrokers.Outbox.MongoDB @@ -23,8 +23,8 @@ - - + + diff --git a/src/Genocs.MessageBrokers.Outbox/Genocs.MessageBrokers.Outbox.csproj b/src/Genocs.MessageBrokers.Outbox/Genocs.MessageBrokers.Outbox.csproj index 40a7ffe0..606ef8c7 100644 --- a/src/Genocs.MessageBrokers.Outbox/Genocs.MessageBrokers.Outbox.csproj +++ b/src/Genocs.MessageBrokers.Outbox/Genocs.MessageBrokers.Outbox.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.MessageBrokers.Outbox Genocs.MessageBrokers.Outbox Genocs.MessageBrokers.Outbox @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.MessageBrokers.RabbitMQ/Genocs.MessageBrokers.RabbitMQ.csproj b/src/Genocs.MessageBrokers.RabbitMQ/Genocs.MessageBrokers.RabbitMQ.csproj index 7ebfcf64..a36b28d6 100644 --- a/src/Genocs.MessageBrokers.RabbitMQ/Genocs.MessageBrokers.RabbitMQ.csproj +++ b/src/Genocs.MessageBrokers.RabbitMQ/Genocs.MessageBrokers.RabbitMQ.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.MessageBrokers.RabbitMQ Genocs.MessageBrokers.RabbitMQ Genocs.MessageBrokers.RabbitMQ @@ -22,12 +22,12 @@ - + - + diff --git a/src/Genocs.MessageBrokers/Genocs.MessageBrokers.csproj b/src/Genocs.MessageBrokers/Genocs.MessageBrokers.csproj index 8cb7ec2c..69fde5a1 100644 --- a/src/Genocs.MessageBrokers/Genocs.MessageBrokers.csproj +++ b/src/Genocs.MessageBrokers/Genocs.MessageBrokers.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.MessageBrokers Genocs.MessageBrokers Genocs.MessageBrokers @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Metrics/Genocs.Metrics.csproj b/src/Genocs.Metrics/Genocs.Metrics.csproj index fa0e7a00..348ea903 100644 --- a/src/Genocs.Metrics/Genocs.Metrics.csproj +++ b/src/Genocs.Metrics/Genocs.Metrics.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Metrics Genocs.Metrics Genocs.Metrics @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Monitoring/Genocs.Monitoring.csproj b/src/Genocs.Monitoring/Genocs.Monitoring.csproj index 0d5d7ff6..ab4afe99 100644 --- a/src/Genocs.Monitoring/Genocs.Monitoring.csproj +++ b/src/Genocs.Monitoring/Genocs.Monitoring.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Monitoring Genocs.Monitoring Genocs.Monitoring @@ -40,9 +40,9 @@ - - - + + + diff --git a/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj b/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj index b564f04d..a4380106 100644 --- a/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj +++ b/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj @@ -1,15 +1,15 @@  - net8.0 + net9.0 false false Genocs - - + + @@ -24,7 +24,7 @@ - + diff --git a/src/Genocs.Persistence.MongoDb/Genocs.Persistence.MongoDb.csproj b/src/Genocs.Persistence.MongoDb/Genocs.Persistence.MongoDb.csproj index 7f9f2b16..f02a1ef6 100644 --- a/src/Genocs.Persistence.MongoDb/Genocs.Persistence.MongoDb.csproj +++ b/src/Genocs.Persistence.MongoDb/Genocs.Persistence.MongoDb.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Persistence.MongoDb Genocs.Persistence.MongoDb Genocs.Persistence.MongoDb @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Persistence.Redis/Genocs.Persistence.Redis.csproj b/src/Genocs.Persistence.Redis/Genocs.Persistence.Redis.csproj index 0b44127c..f653099f 100644 --- a/src/Genocs.Persistence.Redis/Genocs.Persistence.Redis.csproj +++ b/src/Genocs.Persistence.Redis/Genocs.Persistence.Redis.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Persistence.Redis Genocs.Persistence.Redis Genocs.Persistence.Redis @@ -10,7 +10,7 @@ true 5.0.0 Nocco Giovanni Emanuele - aggregate architecture boilerplate ddd ddd-architecture design-patterns docker domain-driven-design dotnet dotnetcore dotnet-core microservice microservices solid solid-principles + redis rediscache design-patterns docker domain-driven-design dotnet dotnetcore dotnet-core microservice microservices solid solid-principles README_NUGET.md Aligned to the ecosystem True @@ -22,11 +22,11 @@ - + - + diff --git a/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj b/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj index e51e8049..24a8d342 100644 --- a/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj +++ b/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj @@ -1,13 +1,13 @@  - net8.0 + net9.0 false false - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -31,8 +31,8 @@ - - + + diff --git a/src/Genocs.Secrets.AzureKeyVault/Genocs.Secrets.AzureKeyVault.csproj b/src/Genocs.Secrets.AzureKeyVault/Genocs.Secrets.AzureKeyVault.csproj index eda6a48d..74abf1cc 100644 --- a/src/Genocs.Secrets.AzureKeyVault/Genocs.Secrets.AzureKeyVault.csproj +++ b/src/Genocs.Secrets.AzureKeyVault/Genocs.Secrets.AzureKeyVault.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Secrets.AzureKeyVault Genocs.Secrets.AzureKeyVault Genocs.Secrets.AzureKeyVault @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Secrets.Vault/Genocs.Secrets.Vault.csproj b/src/Genocs.Secrets.Vault/Genocs.Secrets.Vault.csproj index 61c373ee..4f6bc8d5 100644 --- a/src/Genocs.Secrets.Vault/Genocs.Secrets.Vault.csproj +++ b/src/Genocs.Secrets.Vault/Genocs.Secrets.Vault.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Secrets.Vault Genocs.Secrets.Vault Genocs.Secrets.Vault @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Security/Genocs.Security.csproj b/src/Genocs.Security/Genocs.Security.csproj index 911dec65..d92a361f 100644 --- a/src/Genocs.Security/Genocs.Security.csproj +++ b/src/Genocs.Security/Genocs.Security.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Security Genocs.Security Genocs.Security @@ -22,11 +22,15 @@ - + + + + + - + diff --git a/src/Genocs.ServiceBusAzure.UnitTests/Genocs.ServiceBusAzure.UnitTests.csproj b/src/Genocs.ServiceBusAzure.UnitTests/Genocs.ServiceBusAzure.UnitTests.csproj index bc90559c..9f2b7f07 100644 --- a/src/Genocs.ServiceBusAzure.UnitTests/Genocs.ServiceBusAzure.UnitTests.csproj +++ b/src/Genocs.ServiceBusAzure.UnitTests/Genocs.ServiceBusAzure.UnitTests.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 false false diff --git a/src/Genocs.ServiceBusAzure/Genocs.ServiceBusAzure.csproj b/src/Genocs.ServiceBusAzure/Genocs.ServiceBusAzure.csproj index c2e209e7..a9af0299 100644 --- a/src/Genocs.ServiceBusAzure/Genocs.ServiceBusAzure.csproj +++ b/src/Genocs.ServiceBusAzure/Genocs.ServiceBusAzure.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.ServiceBusAzure Genocs.ServiceBusAzure Genocs.ServiceBusAzure @@ -22,13 +22,13 @@ - + - - + + diff --git a/src/Genocs.Tracing.Jaeger.RabbitMQ/Genocs.Tracing.Jaeger.RabbitMQ.csproj b/src/Genocs.Tracing.Jaeger.RabbitMQ/Genocs.Tracing.Jaeger.RabbitMQ.csproj index 850a07f9..97844c73 100644 --- a/src/Genocs.Tracing.Jaeger.RabbitMQ/Genocs.Tracing.Jaeger.RabbitMQ.csproj +++ b/src/Genocs.Tracing.Jaeger.RabbitMQ/Genocs.Tracing.Jaeger.RabbitMQ.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Tracing.Jaeger.RabbitMQ Genocs.Tracing.Jaeger.RabbitMQ Genocs.Tracing.Jaeger.RabbitMQ @@ -23,8 +23,8 @@ - - + + diff --git a/src/Genocs.Tracing/Extensions.cs b/src/Genocs.Tracing/Extensions.cs index 9ff0aef4..1f91c164 100644 --- a/src/Genocs.Tracing/Extensions.cs +++ b/src/Genocs.Tracing/Extensions.cs @@ -9,6 +9,7 @@ using OpenTelemetry.Metrics; using OpenTelemetry.Resources; using OpenTelemetry.Trace; +using static Genocs.Core.Exceptions.GenocsException; namespace Genocs.Tracing; @@ -25,21 +26,15 @@ public static class Extensions /// The Genocs builder you can use for chain. public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder) { - - AppOptions options = builder.GetOptions(AppOptions.Position); + AppOptions appOptions = builder.GetOptions(AppOptions.Position) + ?? throw new InvalidConfigurationException("app config section is missing. AddOpenTelemetry requires those configuration."); // No OpenTelemetryTracing in case of missing ServiceName - if (string.IsNullOrWhiteSpace(options.Service)) + if (string.IsNullOrWhiteSpace(appOptions.Service)) { return builder; } - //builder.Logging.AddOpenTelemetry(logging => - //{ - // logging.IncludeFormattedMessage = true; - // logging.IncludeScopes = true; - //}); - LoggerOptions loggerOptions = builder.GetOptions(LoggerOptions.Position); if (loggerOptions is null) @@ -47,6 +42,13 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder) return builder; } + // OpenTelemetry Logging + builder.WebApplicationBuilder?.Logging.AddOpenTelemetry(logging => + { + logging.IncludeFormattedMessage = true; + logging.IncludeScopes = true; + }); + var services = builder.Services; // Set Custom Open telemetry @@ -54,7 +56,10 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder) .WithTracing(x => { TracerProviderBuilder provider = x.SetResourceBuilder(ResourceBuilder.CreateDefault() - .AddService(serviceName: options.Service, serviceVersion: options.Version, serviceInstanceId: options.Instance) + .AddService( + serviceName: appOptions.Service, + serviceVersion: appOptions.Version, + serviceInstanceId: appOptions.Instance) .AddTelemetrySdk() .AddEnvironmentVariableDetector()) .AddAspNetCoreInstrumentation() @@ -62,14 +67,14 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder) .AddSource("*"); // No OpenTelemetryTracing in case of missing LoggerSettings - if (loggerOptions.Mongo != null && loggerOptions.Mongo.Enabled) + if (loggerOptions.Mongo?.Enabled == true) { // Check for MongoDB config provider.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources"); } // Check for Console config - if (loggerOptions.Console != null && loggerOptions.Console.Enabled) + if (loggerOptions.Console?.Enabled == true && loggerOptions.Console.EnableTracing) { // you should add OpenTelemetry.Exporter.Console NuGet package // Any OTEL supportable exporter can be used here @@ -77,7 +82,7 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder) } // Check for Azure ApplicationInsights config - if (loggerOptions.Azure != null && loggerOptions.Azure.Enabled) + if (loggerOptions.Azure?.Enabled == true && loggerOptions.Azure.EnableTracing) { provider.AddAzureMonitorTraceExporter(o => { @@ -87,7 +92,7 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder) var jaegerOptions = builder.GetOptions(JaegerOptions.Position); - if (jaegerOptions != null && jaegerOptions.Enabled) + if (jaegerOptions?.Enabled == true) { provider.AddOtlpExporter(o => { @@ -130,13 +135,12 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder) provider.AddAspNetCoreInstrumentation(); - // provider.AddRuntimeInstrumentation(); + provider.AddRuntimeInstrumentation(); provider.AddHttpClientInstrumentation(); provider.AddOtlpExporter(); - // Check for Console config - if (loggerOptions.Console != null && loggerOptions.Console.Enabled) + if (loggerOptions.Console?.Enabled == true && loggerOptions.Console.EnableMetrics) { // you should add OpenTelemetry.Exporter.Console NuGet package // Any OTEL supportable exporter can be used here @@ -144,7 +148,7 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder) } // Check for Azure ApplicationInsights config - if (loggerOptions.Azure != null && loggerOptions.Azure.Enabled) + if (loggerOptions.Azure?.Enabled == true) { provider.AddAzureMonitorMetricExporter(o => { diff --git a/src/Genocs.Tracing/Genocs.Tracing.csproj b/src/Genocs.Tracing/Genocs.Tracing.csproj index 5c92a7dd..58890d57 100644 --- a/src/Genocs.Tracing/Genocs.Tracing.csproj +++ b/src/Genocs.Tracing/Genocs.Tracing.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.Tracing Genocs.Tracing Genocs.Tracing @@ -24,9 +24,9 @@ - - - + + + @@ -36,6 +36,8 @@ + + diff --git a/src/Genocs.WebApi.CQRS/Genocs.WebApi.CQRS.csproj b/src/Genocs.WebApi.CQRS/Genocs.WebApi.CQRS.csproj index f43a5c4c..d48a85c7 100644 --- a/src/Genocs.WebApi.CQRS/Genocs.WebApi.CQRS.csproj +++ b/src/Genocs.WebApi.CQRS/Genocs.WebApi.CQRS.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.WebApi.CQRS Genocs.WebApi.CQRS Genocs.WebApi.CQRS @@ -23,8 +23,8 @@ - - + + diff --git a/src/Genocs.WebApi.Security/Genocs.WebApi.Security.csproj b/src/Genocs.WebApi.Security/Genocs.WebApi.Security.csproj index e5767a51..6ad6611d 100644 --- a/src/Genocs.WebApi.Security/Genocs.WebApi.Security.csproj +++ b/src/Genocs.WebApi.Security/Genocs.WebApi.Security.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.WebApi.Security Genocs.WebApi.Security Genocs.WebApi.Security @@ -22,9 +22,13 @@ - + + + + + diff --git a/src/Genocs.WebApi.Swagger/Genocs.WebApi.Swagger.csproj b/src/Genocs.WebApi.Swagger/Genocs.WebApi.Swagger.csproj index c794b33e..78b7f717 100644 --- a/src/Genocs.WebApi.Swagger/Genocs.WebApi.Swagger.csproj +++ b/src/Genocs.WebApi.Swagger/Genocs.WebApi.Swagger.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.WebApi.Swagger Genocs.WebApi.Swagger Genocs.WebApi.Swagger @@ -10,7 +10,7 @@ true 5.0.0 Nocco Giovanni Emanuele - aggregate architecture boilerplate ddd ddd-architecture design-patterns docker domain-driven-design dotnet dotnetcore dotnet-core microservice microservices solid solid-principles + openapi open api design-patterns docker domain-driven-design dotnet dotnetcore dotnet-core microservice microservices solid solid-principles README_NUGET.md Aligned to the ecosystem True @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.WebApi/Genocs.WebApi.csproj b/src/Genocs.WebApi/Genocs.WebApi.csproj index aa0b5a0c..ac93a765 100644 --- a/src/Genocs.WebApi/Genocs.WebApi.csproj +++ b/src/Genocs.WebApi/Genocs.WebApi.csproj @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0 + net9.0;net8.0;net7.0;net6.0 Genocs.WebApi Genocs.WebApi Genocs.WebApi @@ -22,7 +22,7 @@ - + diff --git a/src/apps/api-gateway/Genocs.APIGateway/Genocs.APIGateway.csproj b/src/apps/api-gateway/Genocs.APIGateway/Genocs.APIGateway.csproj index 6d8537c6..99064554 100644 --- a/src/apps/api-gateway/Genocs.APIGateway/Genocs.APIGateway.csproj +++ b/src/apps/api-gateway/Genocs.APIGateway/Genocs.APIGateway.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 false false @@ -19,18 +19,19 @@ - - - - - - - - - + + + + + + + + + + diff --git a/src/apps/api-gateway/Genocs.APIGateway/Startup.cs b/src/apps/api-gateway/Genocs.APIGateway/Startup.cs index 0cb08426..0433677e 100644 --- a/src/apps/api-gateway/Genocs.APIGateway/Startup.cs +++ b/src/apps/api-gateway/Genocs.APIGateway/Startup.cs @@ -1,13 +1,11 @@ using Genocs.APIGateway.Configurations; using Genocs.APIGateway.Framework; using Genocs.Auth; -using Genocs.Common.Configurations; using Genocs.Core.Builders; using Genocs.MessageBrokers.RabbitMQ; using Genocs.Metrics.Prometheus; using Genocs.Security; using Genocs.Tracing; -using Genocs.Tracing.Jaeger; using Genocs.WebApi; using Yarp.ReverseProxy.Forwarder; @@ -83,15 +81,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseRouting(); app.UseAuthorization(); + app.MapDefaultEndpoints(); + app.UseEndpoints(endpoints => { - endpoints.MapGet("/", async context => - { - await context.Response.WriteAsync(context.RequestServices.GetService()?.Name ?? "Service"); - }); endpoints.MapReverseProxy(); - - endpoints.MapHealthChecks("/hc"); }); } } diff --git a/src/apps/identity/Genocs.Identities.Application/Genocs.Identities.Application.csproj b/src/apps/identity/Genocs.Identities.Application/Genocs.Identities.Application.csproj index 9704def8..4e3c8dca 100644 --- a/src/apps/identity/Genocs.Identities.Application/Genocs.Identities.Application.csproj +++ b/src/apps/identity/Genocs.Identities.Application/Genocs.Identities.Application.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 false false @@ -20,16 +20,20 @@ - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/apps/identity/Genocs.Identities.WebApi/Genocs.Identities.WebApi.csproj b/src/apps/identity/Genocs.Identities.WebApi/Genocs.Identities.WebApi.csproj index 1a601e87..99432ecb 100644 --- a/src/apps/identity/Genocs.Identities.WebApi/Genocs.Identities.WebApi.csproj +++ b/src/apps/identity/Genocs.Identities.WebApi/Genocs.Identities.WebApi.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 false false _genocs @@ -21,4 +21,8 @@ + + + + diff --git a/src/apps/orders/Genocs.Orders.WebApi/Genocs.Orders.WebApi.csproj b/src/apps/orders/Genocs.Orders.WebApi/Genocs.Orders.WebApi.csproj index 7018f219..f161c38d 100644 --- a/src/apps/orders/Genocs.Orders.WebApi/Genocs.Orders.WebApi.csproj +++ b/src/apps/orders/Genocs.Orders.WebApi/Genocs.Orders.WebApi.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 false false _genocs @@ -29,22 +29,26 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/src/apps/products/Genocs.Products.WebApi/Genocs.Products.WebApi.csproj b/src/apps/products/Genocs.Products.WebApi/Genocs.Products.WebApi.csproj index 499fbed1..d54c84eb 100644 --- a/src/apps/products/Genocs.Products.WebApi/Genocs.Products.WebApi.csproj +++ b/src/apps/products/Genocs.Products.WebApi/Genocs.Products.WebApi.csproj @@ -1,12 +1,10 @@  - net8.0 + net9.0 false false - _genocs - Linux - ..\.. + _Genocs @@ -30,22 +28,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -53,4 +51,8 @@ + + + + diff --git a/src/apps/signalr/Genocs.SignalR.WebApi/Genocs.SignalR.WebApi.csproj b/src/apps/signalr/Genocs.SignalR.WebApi/Genocs.SignalR.WebApi.csproj index 6409fb9b..cd7c71e7 100644 --- a/src/apps/signalr/Genocs.SignalR.WebApi/Genocs.SignalR.WebApi.csproj +++ b/src/apps/signalr/Genocs.SignalR.WebApi/Genocs.SignalR.WebApi.csproj @@ -1,12 +1,10 @@  - net8.0 + net9.0 false false - _genocs - Linux - ..\.. + _Genocs @@ -31,26 +29,30 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/apps/signalr/Genocs.SignalR.WebApi/Program.cs b/src/apps/signalr/Genocs.SignalR.WebApi/Program.cs index b0406060..816d944c 100644 --- a/src/apps/signalr/Genocs.SignalR.WebApi/Program.cs +++ b/src/apps/signalr/Genocs.SignalR.WebApi/Program.cs @@ -16,7 +16,6 @@ using Genocs.SignalR.WebApi.Hubs; using Genocs.SignalR.WebApi.Services; using Genocs.Tracing; -using Genocs.Tracing.Jaeger; using Genocs.WebApi; using Genocs.WebApi.CQRS; using Genocs.WebApi.Swagger;