diff --git a/booking-microservices.sln b/booking-microservices.sln index 90aea0d..fdef5ab 100644 --- a/booking-microservices.sln +++ b/booking-microservices.sln @@ -75,6 +75,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C4287034-683 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppHost", "src\Aspire\src\AppHost\AppHost.csproj", "{490BCB11-314C-473C-9B85-A32164783507}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceDefaults", "src\Aspire\src\ServiceDefaults\ServiceDefaults.csproj", "{5B7BF918-E47F-4932-B5C5-E8C2C35890E4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -289,6 +291,18 @@ Global {490BCB11-314C-473C-9B85-A32164783507}.Release|x64.Build.0 = Release|Any CPU {490BCB11-314C-473C-9B85-A32164783507}.Release|x86.ActiveCfg = Release|Any CPU {490BCB11-314C-473C-9B85-A32164783507}.Release|x86.Build.0 = Release|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Debug|x64.ActiveCfg = Debug|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Debug|x64.Build.0 = Debug|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Debug|x86.ActiveCfg = Debug|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Debug|x86.Build.0 = Debug|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Release|Any CPU.Build.0 = Release|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Release|x64.ActiveCfg = Release|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Release|x64.Build.0 = Release|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Release|x86.ActiveCfg = Release|Any CPU + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -329,5 +343,6 @@ Global {D1B6353A-63F5-4DD9-90E6-42B2CFDF1DEA} = {CD4A4407-C3B0-422D-BB8C-2A810CED9938} {C4287034-6833-4505-A6EB-704A86392ECB} = {D1B6353A-63F5-4DD9-90E6-42B2CFDF1DEA} {490BCB11-314C-473C-9B85-A32164783507} = {C4287034-6833-4505-A6EB-704A86392ECB} + {5B7BF918-E47F-4932-B5C5-E8C2C35890E4} = {C4287034-6833-4505-A6EB-704A86392ECB} EndGlobalSection EndGlobal diff --git a/src/ApiGateway/src/Program.cs b/src/ApiGateway/src/Program.cs index 2deb748..a61bf0d 100644 --- a/src/ApiGateway/src/Program.cs +++ b/src/ApiGateway/src/Program.cs @@ -7,7 +7,6 @@ var appOptions = builder.Services.GetOptions("AppOptions"); Console.WriteLine(FiggleFonts.Standard.Render(appOptions.Name)); - builder.Services.AddControllers(); builder.Services.AddHttpContextAccessor(); diff --git a/src/Aspire/src/ServiceDefaults/Extensions.cs b/src/Aspire/src/ServiceDefaults/Extensions.cs new file mode 100644 index 0000000..2d7a43e --- /dev/null +++ b/src/Aspire/src/ServiceDefaults/Extensions.cs @@ -0,0 +1,40 @@ +using BuildingBlocks.HealthCheck; +using BuildingBlocks.OpenTelemetryCollector; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.Extensions.Hosting; + +public static class Extensions +{ + public static IHostApplicationBuilder AddServiceDefaults(this WebApplicationBuilder builder) + { + builder.Services.AddCustomHealthCheck(); + builder.AddCustomObservability(); + builder.Services.AddServiceDiscovery(); + + builder.Services.ConfigureHttpClientDefaults(http => + { + http.AddStandardResilienceHandler(options => + { + var timeSpan = TimeSpan.FromMinutes(1); + options.CircuitBreaker.SamplingDuration = timeSpan * 2; + options.TotalRequestTimeout.Timeout = timeSpan * 3; + options.Retry.MaxRetryAttempts = 3; + }); + + // Turn on service discovery by default + http.AddServiceDiscovery(); + }); + + return builder; + } + + public static WebApplication UseServiceDefaults(this WebApplication app) + { + app.UseCustomHealthCheck(); + app.UseCustomObservability(); + + return app; + } +} \ No newline at end of file diff --git a/src/Aspire/src/ServiceDefaults/ServiceDefaults.csproj b/src/Aspire/src/ServiceDefaults/ServiceDefaults.csproj new file mode 100644 index 0000000..fb67635 --- /dev/null +++ b/src/Aspire/src/ServiceDefaults/ServiceDefaults.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/src/Services/Booking/src/Booking/Booking.csproj b/src/Services/Booking/src/Booking/Booking.csproj index e4418df..496a346 100644 --- a/src/Services/Booking/src/Booking/Booking.csproj +++ b/src/Services/Booking/src/Booking/Booking.csproj @@ -14,6 +14,7 @@ + diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs index 4f14e9b..1826bce 100644 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -28,25 +28,7 @@ public static class InfrastructureExtensions var configuration = builder.Configuration; var env = builder.Environment; - builder.Services.AddCustomHealthCheck(); - - builder.AddCustomObservability(); - - builder.Services.AddServiceDiscovery(); - - builder.Services.ConfigureHttpClientDefaults(http => - { - http.AddStandardResilienceHandler(options => - { - var timeSpan = TimeSpan.FromMinutes(1); - options.CircuitBreaker.SamplingDuration = timeSpan * 2; - options.TotalRequestTimeout.Timeout = timeSpan * 3; - options.Retry.MaxRetryAttempts = 3; - }); - - // Turn on service discovery by default - http.AddServiceDiscovery(); - }); + builder.AddServiceDefaults(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -94,8 +76,7 @@ public static class InfrastructureExtensions app.UseAuthentication(); app.UseAuthorization(); - app.UseCustomHealthCheck(); - app.UseCustomObservability(); + app.UseServiceDefaults(); app.UseCustomProblemDetails(); app.UseCorrelationId(); diff --git a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs index 99c83fa..eff8628 100644 --- a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -32,25 +32,7 @@ public static class InfrastructureExtensions var configuration = builder.Configuration; var env = builder.Environment; - builder.Services.AddCustomHealthCheck(); - - builder.AddCustomObservability(); - - builder.Services.AddServiceDiscovery(); - - builder.Services.ConfigureHttpClientDefaults(http => - { - http.AddStandardResilienceHandler(options => - { - var timeSpan = TimeSpan.FromMinutes(1); - options.CircuitBreaker.SamplingDuration = timeSpan * 2; - options.TotalRequestTimeout.Timeout = timeSpan * 3; - options.Retry.MaxRetryAttempts = 3; - }); - - // Turn on service discovery by default - http.AddServiceDiscovery(); - }); + builder.AddServiceDefaults(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -100,8 +82,7 @@ public static class InfrastructureExtensions app.UseAuthentication(); app.UseAuthorization(); - app.UseCustomHealthCheck(); - app.UseCustomObservability(); + app.UseServiceDefaults(); app.UseCustomProblemDetails(); app.UseCorrelationId(); diff --git a/src/Services/Flight/src/Flight/Flight.csproj b/src/Services/Flight/src/Flight/Flight.csproj index 7a524e0..adf24bf 100644 --- a/src/Services/Flight/src/Flight/Flight.csproj +++ b/src/Services/Flight/src/Flight/Flight.csproj @@ -22,6 +22,7 @@ + diff --git a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs index d2b8727..0b8e094 100644 --- a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -28,25 +28,7 @@ public static class InfrastructureExtensions var configuration = builder.Configuration; var env = builder.Environment; - builder.Services.AddCustomHealthCheck(); - - builder.AddCustomObservability(); - - builder.Services.AddServiceDiscovery(); - - builder.Services.ConfigureHttpClientDefaults(http => - { - http.AddStandardResilienceHandler(options => - { - var timeSpan = TimeSpan.FromMinutes(1); - options.CircuitBreaker.SamplingDuration = timeSpan * 2; - options.TotalRequestTimeout.Timeout = timeSpan * 3; - options.Retry.MaxRetryAttempts = 3; - }); - - // Turn on service discovery by default - http.AddServiceDiscovery(); - }); + builder.AddServiceDefaults(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -94,8 +76,7 @@ public static class InfrastructureExtensions app.UseAuthentication(); app.UseAuthorization(); - app.UseCustomHealthCheck(); - app.UseCustomObservability(); + app.UseServiceDefaults(); app.UseForwardedHeaders(); diff --git a/src/Services/Identity/src/Identity/Identity.csproj b/src/Services/Identity/src/Identity/Identity.csproj index 18ea371..9f43a71 100644 --- a/src/Services/Identity/src/Identity/Identity.csproj +++ b/src/Services/Identity/src/Identity/Identity.csproj @@ -12,6 +12,7 @@ + diff --git a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs index 67d8b54..b1b3298 100644 --- a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -30,26 +30,7 @@ public static class InfrastructureExtensions var configuration = builder.Configuration; var env = builder.Environment; - builder.Services.AddCustomHealthCheck(); - - builder.AddCustomObservability(); - - builder.Services.AddServiceDiscovery(); - - builder.Services.ConfigureHttpClientDefaults(http => - { - http.AddStandardResilienceHandler(options => - { - var timeSpan = TimeSpan.FromMinutes(1); - options.CircuitBreaker.SamplingDuration = timeSpan * 2; - options.TotalRequestTimeout.Timeout = timeSpan * 3; - options.Retry.MaxRetryAttempts = 3; - }); - - // Turn on service discovery by default - http.AddServiceDiscovery(); - }); - + builder.AddServiceDefaults(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -97,8 +78,7 @@ public static class InfrastructureExtensions app.UseAuthentication(); app.UseAuthorization(); - app.UseCustomHealthCheck(); - app.UseCustomObservability(); + app.UseServiceDefaults(); app.UseCustomProblemDetails(); diff --git a/src/Services/Passenger/src/Passenger/Passenger.csproj b/src/Services/Passenger/src/Passenger/Passenger.csproj index b19c894..d73aa16 100644 --- a/src/Services/Passenger/src/Passenger/Passenger.csproj +++ b/src/Services/Passenger/src/Passenger/Passenger.csproj @@ -17,6 +17,7 @@ +