diff --git a/CleanArchitecture.Api/Program.cs b/CleanArchitecture.Api/Program.cs
index 4d67701..95c2bb1 100644
--- a/CleanArchitecture.Api/Program.cs
+++ b/CleanArchitecture.Api/Program.cs
@@ -6,6 +6,7 @@
using CleanArchitecture.Domain.Rabbitmq.Extensions;
using CleanArchitecture.Infrastructure.Database;
using CleanArchitecture.Infrastructure.Extensions;
+using CleanArchitecture.ServiceDefaults;
using HealthChecks.ApplicationStatus.DependencyInjection;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Builder;
diff --git a/CleanArchitecture.Api/Properties/launchSettings.json b/CleanArchitecture.Api/Properties/launchSettings.json
index 7a96097..5b148db 100644
--- a/CleanArchitecture.Api/Properties/launchSettings.json
+++ b/CleanArchitecture.Api/Properties/launchSettings.json
@@ -1,13 +1,5 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
- "iisSettings": {
- "windowsAuthentication": false,
- "anonymousAuthentication": true,
- "iisExpress": {
- "applicationUrl": "http://localhost:38452",
- "sslPort": 44309
- }
- },
"profiles": {
"CleanArchitecture.Api": {
"commandName": "Project",
@@ -18,14 +10,6 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
- },
- "IIS Express": {
- "commandName": "IISExpress",
- "launchBrowser": true,
- "launchUrl": "swagger",
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- }
}
}
}
diff --git a/CleanArchitecture.AppHost/CleanArchitecture.AppHost.csproj b/CleanArchitecture.AppHost/CleanArchitecture.AppHost.csproj
index d218d15..74a66dc 100644
--- a/CleanArchitecture.AppHost/CleanArchitecture.AppHost.csproj
+++ b/CleanArchitecture.AppHost/CleanArchitecture.AppHost.csproj
@@ -13,6 +13,9 @@
+
+
+
diff --git a/CleanArchitecture.AppHost/Program.cs b/CleanArchitecture.AppHost/Program.cs
index 24d649f..261b990 100644
--- a/CleanArchitecture.AppHost/Program.cs
+++ b/CleanArchitecture.AppHost/Program.cs
@@ -1,5 +1,26 @@
var builder = DistributedApplication.CreateBuilder(args);
-builder.AddProject("cleanarchitecture-api");
+var redis = builder.AddRedis("Redis");
+
+var rabbitPasswordRessource = new ParameterResource("password", _ => "guest");
+var rabbitPasswordParameter =
+ builder.AddParameter("username", rabbitPasswordRessource.Value);
+
+var rabbitMq = builder
+ .AddRabbitMQ("RabbitMq", null, rabbitPasswordParameter, 5672)
+ .WithManagementPlugin();
+
+var sqlServer = builder.AddSqlServer("SqlServer");
+
+builder.AddProject("CleanArchitecture.Api")
+ .WithHttpsEndpoint(17270)
+ .WithHealthCheck("Api Health")
+ .WithOtlpExporter()
+ .WithReference(redis)
+ .WaitFor(redis)
+ .WithReference(rabbitMq)
+ .WaitFor(rabbitMq)
+ .WithReference(sqlServer)
+ .WaitFor(sqlServer);
builder.Build().Run();
diff --git a/CleanArchitecture.AppHost/Properties/launchSettings.json b/CleanArchitecture.AppHost/Properties/launchSettings.json
index 32376b9..030b6d4 100644
--- a/CleanArchitecture.AppHost/Properties/launchSettings.json
+++ b/CleanArchitecture.AppHost/Properties/launchSettings.json
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
- "https": {
+ "Aspire": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
@@ -10,19 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21200",
- "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22111"
- }
- },
- "http": {
- "commandName": "Project",
- "dotnetRunMessages": true,
- "launchBrowser": true,
- "applicationUrl": "http://localhost:15188",
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development",
- "DOTNET_ENVIRONMENT": "Development",
- "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19170",
- "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20198"
+ "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22111",
+ "ASPIRE_ENABLED": "true"
}
}
}
diff --git a/CleanArchitecture.ServiceDefaults/CleanArchitecture.ServiceDefaults.csproj b/CleanArchitecture.ServiceDefaults/CleanArchitecture.ServiceDefaults.csproj
index e86dfa4..ccc2414 100644
--- a/CleanArchitecture.ServiceDefaults/CleanArchitecture.ServiceDefaults.csproj
+++ b/CleanArchitecture.ServiceDefaults/CleanArchitecture.ServiceDefaults.csproj
@@ -15,6 +15,7 @@
+
diff --git a/CleanArchitecture.ServiceDefaults/Extensions.cs b/CleanArchitecture.ServiceDefaults/Extensions.cs
index 13151bf..c6dc3d3 100644
--- a/CleanArchitecture.ServiceDefaults/Extensions.cs
+++ b/CleanArchitecture.ServiceDefaults/Extensions.cs
@@ -2,21 +2,26 @@
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
+using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ServiceDiscovery;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
-namespace Microsoft.Extensions.Hosting;
+namespace CleanArchitecture.ServiceDefaults;
-// Adds common .NET 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
{
- public static TBuilder AddServiceDefaults(this TBuilder builder) where TBuilder : IHostApplicationBuilder
+ private const string AspireEnabled = "ASPIRE_ENABLED";
+
+ public static void AddServiceDefaults(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
+ if (builder.Configuration[AspireEnabled] != "true")
+ {
+ return;
+ }
+
builder.ConfigureOpenTelemetry();
builder.AddDefaultHealthChecks();
@@ -25,23 +30,17 @@ public static TBuilder AddServiceDefaults(this TBuilder builder) where
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;
+ builder.Services.Configure(options =>
+ {
+ options.AllowedSchemes = ["https"];
+ });
}
- public static TBuilder ConfigureOpenTelemetry(this TBuilder builder) where TBuilder : IHostApplicationBuilder
+ private static void ConfigureOpenTelemetry(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.Logging.AddOpenTelemetry(logging =>
{
@@ -60,17 +59,14 @@ public static TBuilder ConfigureOpenTelemetry(this TBuilder builder) w
{
tracing.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation()
- // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
- //.AddGrpcClientInstrumentation()
+ .AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});
builder.AddOpenTelemetryExporters();
-
- return builder;
}
- private static TBuilder AddOpenTelemetryExporters(this TBuilder builder) where TBuilder : IHostApplicationBuilder
+ private static void AddOpenTelemetryExporters(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
@@ -78,42 +74,29 @@ private static TBuilder AddOpenTelemetryExporters(this TBuilder builde
{
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
+ private static void 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)
+ public static void 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.Configuration[AspireEnabled] != "true")
+ {
+ return;
+ }
+
if (app.Environment.IsDevelopment())
{
- // 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;
}
}