Skip to content

fix: YARP routing, EnsureCreated, and CorrelationIdMiddleware#35

Open
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1778600660-fix-yarp-ensured-middleware
Open

fix: YARP routing, EnsureCreated, and CorrelationIdMiddleware#35
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1778600660-fix-yarp-ensured-middleware

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot commented May 12, 2026

Summary

Three fixes (plus two bonus fixes discovered during testing) to get all microservices working correctly through the YARP API gateway:

  1. YARP Gateway Routing (src/ApiGateway/appsettings.json): Replaced PathRemovePrefix transforms with PathPattern so public plural paths (e.g. /api/customers) are correctly rewritten to backend singular controller routes (e.g. /api/customer).

  2. EnsureCreated() for 4 services: Added the EnsureCreated() block (already present in Notification) to Identity, Customer, Order, and Product Program.cs files 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.

  3. CorrelationIdMiddleware: Registered Shared.Infrastructure.Middleware.CorrelationIdMiddleware in all 5 service Program.cs files and the API Gateway. Added the Shared.Infrastructure project reference to ApiGateway.csproj (the 5 services already had it).

  4. Fixed Shared project reference paths (bonus): All service .csproj files had incorrect relative paths to Shared projects (../../Shared/ instead of ../../../Shared/). Fixed to resolve correctly in both local and Docker builds.

  5. 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:

  • All 8 containers start and stay running (including retry for PostgreSQL readiness)
  • Gateway routes: /api/customers, /api/orders, /api/products, /api/identity, /api/notifications all return correct responses
  • Direct service access on ports 5001-5005 all working
  • X-Correlation-ID header present in gateway responses

Review & Testing Checklist for Human

  • Run cd src && docker compose up --build — all 8 containers should start and stay healthy
  • curl http://localhost:5000/api/customers returns {"service":"Customer","status":"scaffold"}
  • curl http://localhost:5000/api/orders returns {"service":"Order","status":"scaffold"}
  • curl http://localhost:5000/api/products returns {"service":"Product","status":"scaffold"}
  • curl -v http://localhost:5000/api/customers 2>&1 | grep X-Correlation-ID returns a correlation ID header

Notes

  • The gateway keeps public-facing plural paths but rewrites to singular backend controller routes via PathPattern.
  • Retry logic on EnsureCreated() prevents services from crashing when PostgreSQL isn't ready yet (race condition with depends_on which only waits for container start, not readiness).

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/d9b6eee197954b38ba1055661081c0ca


Open in Devin Review

- 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
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown
Contributor Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants