From 5de0f416baa5894ac0c9d34bd4240671b9266ec6 Mon Sep 17 00:00:00 2001 From: Alex Pedersen Date: Wed, 22 Jul 2026 14:24:55 +0200 Subject: [PATCH] Addet Aspire --- PointOfSale/Pos.AppHost/AppHost.cs | 5 + PointOfSale/Pos.AppHost/Pos.AppHost.csproj | 15 +++ .../Properties/launchSettings.json | 31 +++++ .../Pos.AppHost/appsettings.Development.json | 8 ++ PointOfSale/Pos.AppHost/appsettings.json | 9 ++ PointOfSale/Pos.ServiceDefaults/Extensions.cs | 127 ++++++++++++++++++ .../Pos.ServiceDefaults.csproj | 22 +++ PointOfSale/Pos.sln | 12 ++ PointOfSale/aspire.config.json | 5 + 9 files changed, 234 insertions(+) create mode 100644 PointOfSale/Pos.AppHost/AppHost.cs create mode 100644 PointOfSale/Pos.AppHost/Pos.AppHost.csproj create mode 100644 PointOfSale/Pos.AppHost/Properties/launchSettings.json create mode 100644 PointOfSale/Pos.AppHost/appsettings.Development.json create mode 100644 PointOfSale/Pos.AppHost/appsettings.json create mode 100644 PointOfSale/Pos.ServiceDefaults/Extensions.cs create mode 100644 PointOfSale/Pos.ServiceDefaults/Pos.ServiceDefaults.csproj create mode 100644 PointOfSale/aspire.config.json diff --git a/PointOfSale/Pos.AppHost/AppHost.cs b/PointOfSale/Pos.AppHost/AppHost.cs new file mode 100644 index 0000000..cd47a24 --- /dev/null +++ b/PointOfSale/Pos.AppHost/AppHost.cs @@ -0,0 +1,5 @@ +var builder = DistributedApplication.CreateBuilder(args); + +builder.AddProject("database"); + +builder.Build().Run(); diff --git a/PointOfSale/Pos.AppHost/Pos.AppHost.csproj b/PointOfSale/Pos.AppHost/Pos.AppHost.csproj new file mode 100644 index 0000000..c20c6bc --- /dev/null +++ b/PointOfSale/Pos.AppHost/Pos.AppHost.csproj @@ -0,0 +1,15 @@ + + + + Exe + net10.0 + enable + enable + bf471f42-700e-491e-9def-519245baaaa1 + + + + + + + diff --git a/PointOfSale/Pos.AppHost/Properties/launchSettings.json b/PointOfSale/Pos.AppHost/Properties/launchSettings.json new file mode 100644 index 0000000..ce8195e --- /dev/null +++ b/PointOfSale/Pos.AppHost/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:17208;http://localhost:15295", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21197", + "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23254", + "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22138" + } + }, + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:15295", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19286", + "ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18003", + "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20235" + } + } + } +} diff --git a/PointOfSale/Pos.AppHost/appsettings.Development.json b/PointOfSale/Pos.AppHost/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/PointOfSale/Pos.AppHost/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/PointOfSale/Pos.AppHost/appsettings.json b/PointOfSale/Pos.AppHost/appsettings.json new file mode 100644 index 0000000..31c092a --- /dev/null +++ b/PointOfSale/Pos.AppHost/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Aspire.Hosting.Dcp": "Warning" + } + } +} diff --git a/PointOfSale/Pos.ServiceDefaults/Extensions.cs b/PointOfSale/Pos.ServiceDefaults/Extensions.cs new file mode 100644 index 0000000..b72c875 --- /dev/null +++ b/PointOfSale/Pos.ServiceDefaults/Extensions.cs @@ -0,0 +1,127 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.ServiceDiscovery; +using OpenTelemetry; +using OpenTelemetry.Metrics; +using OpenTelemetry.Trace; + +namespace Microsoft.Extensions.Hosting; + +// Adds common Aspire services: service discovery, resilience, health checks, and OpenTelemetry. +// This project should be referenced by each service project in your solution. +// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults +public static class Extensions +{ + private const string HealthEndpointPath = "/health"; + private const string AlivenessEndpointPath = "/alive"; + + public static TBuilder AddServiceDefaults(this TBuilder builder) where TBuilder : IHostApplicationBuilder + { + builder.ConfigureOpenTelemetry(); + + builder.AddDefaultHealthChecks(); + + builder.Services.AddServiceDiscovery(); + + builder.Services.ConfigureHttpClientDefaults(http => + { + // Turn on resilience by default + http.AddStandardResilienceHandler(); + + // Turn on service discovery by default + http.AddServiceDiscovery(); + }); + + // Uncomment the following to restrict the allowed schemes for service discovery. + // builder.Services.Configure(options => + // { + // options.AllowedSchemes = ["https"]; + // }); + + return builder; + } + + public static TBuilder ConfigureOpenTelemetry(this TBuilder builder) where TBuilder : IHostApplicationBuilder + { + builder.Logging.AddOpenTelemetry(logging => + { + logging.IncludeFormattedMessage = true; + logging.IncludeScopes = true; + }); + + builder.Services.AddOpenTelemetry() + .WithMetrics(metrics => + { + metrics.AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation() + .AddRuntimeInstrumentation(); + }) + .WithTracing(tracing => + { + tracing.AddSource(builder.Environment.ApplicationName) + .AddAspNetCoreInstrumentation(tracing => + // Exclude health check requests from tracing + tracing.Filter = context => + !context.Request.Path.StartsWithSegments(HealthEndpointPath) + && !context.Request.Path.StartsWithSegments(AlivenessEndpointPath) + ) + // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) + //.AddGrpcClientInstrumentation() + .AddHttpClientInstrumentation(); + }); + + builder.AddOpenTelemetryExporters(); + + return builder; + } + + private static TBuilder AddOpenTelemetryExporters(this TBuilder builder) where TBuilder : IHostApplicationBuilder + { + var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]); + + if (useOtlpExporter) + { + builder.Services.AddOpenTelemetry().UseOtlpExporter(); + } + + // Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package) + //if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"])) + //{ + // builder.Services.AddOpenTelemetry() + // .UseAzureMonitor(); + //} + + return builder; + } + + public static TBuilder AddDefaultHealthChecks(this TBuilder builder) where TBuilder : IHostApplicationBuilder + { + builder.Services.AddHealthChecks() + // Add a default liveness check to ensure app is responsive + .AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]); + + return builder; + } + + 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()) + { + // All health checks must pass for app to be considered ready to accept traffic after starting + app.MapHealthChecks(HealthEndpointPath); + + // Only health checks tagged with the "live" tag must pass for app to be considered alive + app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions + { + Predicate = r => r.Tags.Contains("live") + }); + } + + return app; + } +} diff --git a/PointOfSale/Pos.ServiceDefaults/Pos.ServiceDefaults.csproj b/PointOfSale/Pos.ServiceDefaults/Pos.ServiceDefaults.csproj new file mode 100644 index 0000000..4502460 --- /dev/null +++ b/PointOfSale/Pos.ServiceDefaults/Pos.ServiceDefaults.csproj @@ -0,0 +1,22 @@ + + + + net10.0 + enable + enable + true + + + + + + + + + + + + + + + diff --git a/PointOfSale/Pos.sln b/PointOfSale/Pos.sln index 9f12bba..6715249 100644 --- a/PointOfSale/Pos.sln +++ b/PointOfSale/Pos.sln @@ -11,6 +11,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pos", "Pos.Ui\Pos\Pos.cspro EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpsonPrinter", "EpsonPrinterLinux\EpsonPrinter.csproj", "{78FE1FBD-ECDF-0A37-C699-9006AD7DCC6D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pos.AppHost", "Pos.AppHost\Pos.AppHost.csproj", "{53EFB4EB-931D-419B-8399-4E389011076C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pos.ServiceDefaults", "Pos.ServiceDefaults\Pos.ServiceDefaults.csproj", "{EDC882E6-4983-35BD-3357-E433A3E64369}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,6 +33,14 @@ Global {78FE1FBD-ECDF-0A37-C699-9006AD7DCC6D}.Debug|Any CPU.Build.0 = Debug|Any CPU {78FE1FBD-ECDF-0A37-C699-9006AD7DCC6D}.Release|Any CPU.ActiveCfg = Release|Any CPU {78FE1FBD-ECDF-0A37-C699-9006AD7DCC6D}.Release|Any CPU.Build.0 = Release|Any CPU + {53EFB4EB-931D-419B-8399-4E389011076C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {53EFB4EB-931D-419B-8399-4E389011076C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {53EFB4EB-931D-419B-8399-4E389011076C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {53EFB4EB-931D-419B-8399-4E389011076C}.Release|Any CPU.Build.0 = Release|Any CPU + {EDC882E6-4983-35BD-3357-E433A3E64369}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDC882E6-4983-35BD-3357-E433A3E64369}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDC882E6-4983-35BD-3357-E433A3E64369}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EDC882E6-4983-35BD-3357-E433A3E64369}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PointOfSale/aspire.config.json b/PointOfSale/aspire.config.json new file mode 100644 index 0000000..dff2d93 --- /dev/null +++ b/PointOfSale/aspire.config.json @@ -0,0 +1,5 @@ +{ + "appHost": { + "path": "Pos.AppHost/Pos.AppHost.csproj" + } +}