From 78b4cc48127484e3a64ec65245ba7c473f041fee Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 15:45:03 +0000 Subject: [PATCH 1/3] fix: YARP routing, EnsureCreated, and CorrelationIdMiddleware - Fix YARP gateway transforms from PathRemovePrefix to PathPattern so backend singular controller routes are reached correctly - Add EnsureCreated() to Identity, Customer, Order, Product services - Register CorrelationIdMiddleware in all services and gateway - Add Shared.Infrastructure project reference to ApiGateway --- src/ApiGateway/ApiGateway.csproj | 4 ++++ src/ApiGateway/Program.cs | 2 ++ src/ApiGateway/appsettings.json | 10 +++++----- src/Services/Customer/Customer.API/Program.cs | 8 ++++++++ src/Services/Identity/Identity.API/Program.cs | 8 ++++++++ src/Services/Notification/Notification.API/Program.cs | 2 ++ src/Services/Order/Order.API/Program.cs | 8 ++++++++ src/Services/Product/Product.API/Program.cs | 8 ++++++++ 8 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/ApiGateway/ApiGateway.csproj b/src/ApiGateway/ApiGateway.csproj index 6ac003b..c9565a4 100644 --- a/src/ApiGateway/ApiGateway.csproj +++ b/src/ApiGateway/ApiGateway.csproj @@ -10,4 +10,8 @@ + + + + diff --git a/src/ApiGateway/Program.cs b/src/ApiGateway/Program.cs index 89d4860..c1a5407 100644 --- a/src/ApiGateway/Program.cs +++ b/src/ApiGateway/Program.cs @@ -7,6 +7,8 @@ var app = builder.Build(); +app.UseMiddleware(); + app.MapReverseProxy(); app.MapHealthChecks("/healthz"); diff --git a/src/ApiGateway/appsettings.json b/src/ApiGateway/appsettings.json index 74c7ae9..9ebc895 100644 --- a/src/ApiGateway/appsettings.json +++ b/src/ApiGateway/appsettings.json @@ -11,27 +11,27 @@ "identity-route": { "ClusterId": "identity-cluster", "Match": { "Path": "/api/identity/{**catch-all}" }, - "Transforms": [{ "PathRemovePrefix": "/api/identity" }] + "Transforms": [{ "PathPattern": "/api/identity/{**catch-all}" }] }, "customer-route": { "ClusterId": "customer-cluster", "Match": { "Path": "/api/customers/{**catch-all}" }, - "Transforms": [{ "PathRemovePrefix": "/api/customers" }] + "Transforms": [{ "PathPattern": "/api/customer/{**catch-all}" }] }, "order-route": { "ClusterId": "order-cluster", "Match": { "Path": "/api/orders/{**catch-all}" }, - "Transforms": [{ "PathRemovePrefix": "/api/orders" }] + "Transforms": [{ "PathPattern": "/api/order/{**catch-all}" }] }, "product-route": { "ClusterId": "product-cluster", "Match": { "Path": "/api/products/{**catch-all}" }, - "Transforms": [{ "PathRemovePrefix": "/api/products" }] + "Transforms": [{ "PathPattern": "/api/product/{**catch-all}" }] }, "notification-route": { "ClusterId": "notification-cluster", "Match": { "Path": "/api/notifications/{**catch-all}" }, - "Transforms": [{ "PathRemovePrefix": "/api/notifications" }] + "Transforms": [{ "PathPattern": "/api/notification/{**catch-all}" }] } }, "Clusters": { diff --git a/src/Services/Customer/Customer.API/Program.cs b/src/Services/Customer/Customer.API/Program.cs index e46940a..1a0ef41 100644 --- a/src/Services/Customer/Customer.API/Program.cs +++ b/src/Services/Customer/Customer.API/Program.cs @@ -13,6 +13,14 @@ var app = builder.Build(); +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); +} + +app.UseMiddleware(); + if (app.Environment.IsDevelopment()) { app.UseSwagger(); diff --git a/src/Services/Identity/Identity.API/Program.cs b/src/Services/Identity/Identity.API/Program.cs index b475a08..fd696cd 100644 --- a/src/Services/Identity/Identity.API/Program.cs +++ b/src/Services/Identity/Identity.API/Program.cs @@ -13,6 +13,14 @@ var app = builder.Build(); +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); +} + +app.UseMiddleware(); + if (app.Environment.IsDevelopment()) { app.UseSwagger(); diff --git a/src/Services/Notification/Notification.API/Program.cs b/src/Services/Notification/Notification.API/Program.cs index 6219c9c..5ea5451 100644 --- a/src/Services/Notification/Notification.API/Program.cs +++ b/src/Services/Notification/Notification.API/Program.cs @@ -26,6 +26,8 @@ db.Database.EnsureCreated(); } +app.UseMiddleware(); + if (app.Environment.IsDevelopment()) { app.UseSwagger(); diff --git a/src/Services/Order/Order.API/Program.cs b/src/Services/Order/Order.API/Program.cs index 4512675..c9a7fbc 100644 --- a/src/Services/Order/Order.API/Program.cs +++ b/src/Services/Order/Order.API/Program.cs @@ -13,6 +13,14 @@ var app = builder.Build(); +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); +} + +app.UseMiddleware(); + if (app.Environment.IsDevelopment()) { app.UseSwagger(); diff --git a/src/Services/Product/Product.API/Program.cs b/src/Services/Product/Product.API/Program.cs index 73146ef..15c3440 100644 --- a/src/Services/Product/Product.API/Program.cs +++ b/src/Services/Product/Product.API/Program.cs @@ -13,6 +13,14 @@ var app = builder.Build(); +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); +} + +app.UseMiddleware(); + if (app.Environment.IsDevelopment()) { app.UseSwagger(); From 168c1cd64c8f8e672a19b8ae8081bed0878b2aa9 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 15:50:45 +0000 Subject: [PATCH 2/3] fix: correct Shared project reference paths and update gateway Dockerfile - Fix csproj references: ../../Shared -> ../../../Shared (3 levels up from Services/X/X.API/ to src/) - Add Shared.Infrastructure COPY to ApiGateway Dockerfile for Docker build --- src/ApiGateway/Dockerfile | 2 ++ src/Services/Customer/Customer.API/Customer.API.csproj | 4 ++-- src/Services/Identity/Identity.API/Identity.API.csproj | 4 ++-- .../Notification/Notification.API/Notification.API.csproj | 4 ++-- src/Services/Order/Order.API/Order.API.csproj | 4 ++-- src/Services/Product/Product.API/Product.API.csproj | 4 ++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ApiGateway/Dockerfile b/src/ApiGateway/Dockerfile index abe6358..1a12465 100644 --- a/src/ApiGateway/Dockerfile +++ b/src/ApiGateway/Dockerfile @@ -5,8 +5,10 @@ EXPOSE 5000 FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build WORKDIR /src COPY ["ApiGateway/ApiGateway.csproj", "ApiGateway/"] +COPY ["Shared/Shared.Infrastructure/Shared.Infrastructure.csproj", "Shared/Shared.Infrastructure/"] RUN dotnet restore "ApiGateway/ApiGateway.csproj" COPY ApiGateway/ ApiGateway/ +COPY Shared/Shared.Infrastructure/ Shared/Shared.Infrastructure/ WORKDIR "/src/ApiGateway" RUN dotnet build -c Release -o /app/build diff --git a/src/Services/Customer/Customer.API/Customer.API.csproj b/src/Services/Customer/Customer.API/Customer.API.csproj index 8c284d4..4a0b5b7 100644 --- a/src/Services/Customer/Customer.API/Customer.API.csproj +++ b/src/Services/Customer/Customer.API/Customer.API.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/Services/Identity/Identity.API/Identity.API.csproj b/src/Services/Identity/Identity.API/Identity.API.csproj index 9b3e932..c4e24d9 100644 --- a/src/Services/Identity/Identity.API/Identity.API.csproj +++ b/src/Services/Identity/Identity.API/Identity.API.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/Services/Notification/Notification.API/Notification.API.csproj b/src/Services/Notification/Notification.API/Notification.API.csproj index 25b5fb0..1518ca2 100644 --- a/src/Services/Notification/Notification.API/Notification.API.csproj +++ b/src/Services/Notification/Notification.API/Notification.API.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/Services/Order/Order.API/Order.API.csproj b/src/Services/Order/Order.API/Order.API.csproj index 54aad4b..12339d9 100644 --- a/src/Services/Order/Order.API/Order.API.csproj +++ b/src/Services/Order/Order.API/Order.API.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/src/Services/Product/Product.API/Product.API.csproj b/src/Services/Product/Product.API/Product.API.csproj index 68be876..5ff75f3 100644 --- a/src/Services/Product/Product.API/Product.API.csproj +++ b/src/Services/Product/Product.API/Product.API.csproj @@ -7,8 +7,8 @@ - - + + From 57bb5c705a7640fc15992c71f7b99e070859e9e1 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 15:53:53 +0000 Subject: [PATCH 3/3] fix: add retry logic to EnsureCreated for PostgreSQL startup race condition --- src/Services/Customer/Customer.API/Program.cs | 15 ++++++++++++--- src/Services/Identity/Identity.API/Program.cs | 15 ++++++++++++--- .../Notification/Notification.API/Program.cs | 15 ++++++++++++--- src/Services/Order/Order.API/Program.cs | 15 ++++++++++++--- src/Services/Product/Product.API/Program.cs | 15 ++++++++++++--- 5 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/Services/Customer/Customer.API/Program.cs b/src/Services/Customer/Customer.API/Program.cs index 1a0ef41..c8faa0f 100644 --- a/src/Services/Customer/Customer.API/Program.cs +++ b/src/Services/Customer/Customer.API/Program.cs @@ -13,10 +13,19 @@ var app = builder.Build(); -using (var scope = app.Services.CreateScope()) +for (var retries = 0; ; retries++) { - var db = scope.ServiceProvider.GetRequiredService(); - db.Database.EnsureCreated(); + try + { + using var scope = app.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); + break; + } + catch (Exception) when (retries < 5) + { + Thread.Sleep(2000); + } } app.UseMiddleware(); diff --git a/src/Services/Identity/Identity.API/Program.cs b/src/Services/Identity/Identity.API/Program.cs index fd696cd..9ee5a6a 100644 --- a/src/Services/Identity/Identity.API/Program.cs +++ b/src/Services/Identity/Identity.API/Program.cs @@ -13,10 +13,19 @@ var app = builder.Build(); -using (var scope = app.Services.CreateScope()) +for (var retries = 0; ; retries++) { - var db = scope.ServiceProvider.GetRequiredService(); - db.Database.EnsureCreated(); + try + { + using var scope = app.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); + break; + } + catch (Exception) when (retries < 5) + { + Thread.Sleep(2000); + } } app.UseMiddleware(); diff --git a/src/Services/Notification/Notification.API/Program.cs b/src/Services/Notification/Notification.API/Program.cs index 5ea5451..94ddf15 100644 --- a/src/Services/Notification/Notification.API/Program.cs +++ b/src/Services/Notification/Notification.API/Program.cs @@ -20,10 +20,19 @@ var app = builder.Build(); -using (var scope = app.Services.CreateScope()) +for (var retries = 0; ; retries++) { - var db = scope.ServiceProvider.GetRequiredService(); - db.Database.EnsureCreated(); + try + { + using var scope = app.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); + break; + } + catch (Exception) when (retries < 5) + { + Thread.Sleep(2000); + } } app.UseMiddleware(); diff --git a/src/Services/Order/Order.API/Program.cs b/src/Services/Order/Order.API/Program.cs index c9a7fbc..1435f8c 100644 --- a/src/Services/Order/Order.API/Program.cs +++ b/src/Services/Order/Order.API/Program.cs @@ -13,10 +13,19 @@ var app = builder.Build(); -using (var scope = app.Services.CreateScope()) +for (var retries = 0; ; retries++) { - var db = scope.ServiceProvider.GetRequiredService(); - db.Database.EnsureCreated(); + try + { + using var scope = app.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); + break; + } + catch (Exception) when (retries < 5) + { + Thread.Sleep(2000); + } } app.UseMiddleware(); diff --git a/src/Services/Product/Product.API/Program.cs b/src/Services/Product/Product.API/Program.cs index 15c3440..ee00179 100644 --- a/src/Services/Product/Product.API/Program.cs +++ b/src/Services/Product/Product.API/Program.cs @@ -13,10 +13,19 @@ var app = builder.Build(); -using (var scope = app.Services.CreateScope()) +for (var retries = 0; ; retries++) { - var db = scope.ServiceProvider.GetRequiredService(); - db.Database.EnsureCreated(); + try + { + using var scope = app.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); + break; + } + catch (Exception) when (retries < 5) + { + Thread.Sleep(2000); + } } app.UseMiddleware();