fix: YARP routing, EnsureCreated, and CorrelationIdMiddleware#35
Open
devin-ai-integration[bot] wants to merge 3 commits into
Open
fix: YARP routing, EnsureCreated, and CorrelationIdMiddleware#35devin-ai-integration[bot] wants to merge 3 commits into
devin-ai-integration[bot] wants to merge 3 commits into
Conversation
- 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
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…file - 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three fixes (plus two bonus fixes discovered during testing) to get all microservices working correctly through the YARP API gateway:
YARP Gateway Routing (
src/ApiGateway/appsettings.json): ReplacedPathRemovePrefixtransforms withPathPatternso public plural paths (e.g./api/customers) are correctly rewritten to backend singular controller routes (e.g./api/customer).EnsureCreated() for 4 services: Added the
EnsureCreated()block (already present in Notification) to Identity, Customer, Order, and ProductProgram.csfiles so their database schemas are auto-created on startup. Added retry logic (up to 5 retries with 2s delay) to all 5 services to handle PostgreSQL startup race conditions.CorrelationIdMiddleware: Registered
Shared.Infrastructure.Middleware.CorrelationIdMiddlewarein all 5 serviceProgram.csfiles and the API Gateway. Added theShared.Infrastructureproject reference toApiGateway.csproj(the 5 services already had it).Fixed Shared project reference paths (bonus): All service
.csprojfiles had incorrect relative paths to Shared projects (../../Shared/instead of../../../Shared/). Fixed to resolve correctly in both local and Docker builds.Updated ApiGateway Dockerfile (bonus): Added COPY commands for Shared.Infrastructure project files so the gateway can build with the new project reference.
Verified locally with Docker Compose:
/api/customers,/api/orders,/api/products,/api/identity,/api/notificationsall return correct responsesX-Correlation-IDheader present in gateway responsesReview & Testing Checklist for Human
cd src && docker compose up --build— all 8 containers should start and stay healthycurl http://localhost:5000/api/customersreturns{"service":"Customer","status":"scaffold"}curl http://localhost:5000/api/ordersreturns{"service":"Order","status":"scaffold"}curl http://localhost:5000/api/productsreturns{"service":"Product","status":"scaffold"}curl -v http://localhost:5000/api/customers 2>&1 | grep X-Correlation-IDreturns a correlation ID headerNotes
PathPattern.EnsureCreated()prevents services from crashing when PostgreSQL isn't ready yet (race condition withdepends_onwhich only waits for container start, not readiness).Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/d9b6eee197954b38ba1055661081c0ca