Skip to content

refactor: Replace in-process Inventory calls with HTTP client to inventory microservice#248

Open
devin-ai-integration[bot] wants to merge 1 commit intodevin/1773358765-initial-monolithfrom
workshop-maharajan_iyadurai
Open

refactor: Replace in-process Inventory calls with HTTP client to inventory microservice#248
devin-ai-integration[bot] wants to merge 1 commit intodevin/1773358765-initial-monolithfrom
workshop-maharajan_iyadurai

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

Decomposes the Inventory module out of the monolith by replacing all direct database access (InventoryService + AppDbContext.InventoryItems) with an HTTP client (InventoryHttpClient) that calls the new standalone inventory microservice.

What changed:

  • Deleted InventoryService.cs (direct DB access) → Added InventoryHttpClient.cs (HTTP calls to inventory-service API)
  • Removed InventoryItems DbSet and entity configuration from AppDbContext
  • Removed inventory seed data from SeedData.cs (now owned by the microservice)
  • Removed Product.Inventory navigation property; InventoryItem model retained as a DTO
  • Updated OrderService.CreateOrderAsync to call InventoryHttpClient.DeductStockAsync instead of deducting directly from DB
  • Updated ProductService to remove .Include(p => p.Inventory) from all queries
  • Registered InventoryHttpClient via AddHttpClient<> in Program.cs with configurable InventoryService:BaseUrl
  • Rewrote tests to use Moq for HTTP handler mocking

Review & Testing Checklist for Human

  • Partial failure / no compensation: CreateOrderAsync loops over items calling DeductStockAsync for each. If the 2nd deduction fails after the 1st succeeded, the 1st deduction is NOT rolled back on the microservice. Verify this is acceptable or add a saga/compensation pattern.
  • No retry or circuit-breaker policy: InventoryHttpClient has no Polly/resilience pipeline. A transient network failure will immediately fail order creation. Consider whether AddStandardResilienceHandler() or similar should be added.
  • JSON contract compatibility: The client sends new { quantity } (camelCase) and reads ErrorResponse(string Error) (PascalCase). Verify the inventory microservice's serialization settings match — mismatches will silently produce null/default values.
  • No EF migration: The InventoryItems table is removed from the DbContext but no migration drops it. Confirm this is intentional (table stays until microservice is validated) or add a migration.
  • Test the full flow end-to-end: Start both the monolith (port 5000) and the inventory microservice (port 5001), then create an order through the monolith API and verify stock is deducted on the microservice side.

Notes

  • The InventoryService:BaseUrl defaults to http://localhost:5001 if not configured. In deployed environments, this must be set to the inventory-service's internal cluster URL.
  • Test coverage only validates OrderService behavior via mocked HTTP. There are no integration tests for InventoryHttpClient itself (error handling, deserialization edge cases).

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

…entory microservice

- Replace InventoryService with InventoryHttpClient that calls the new inventory-service API
- Update InventoryController to proxy requests through InventoryHttpClient
- Update OrderService to deduct stock via HTTP call instead of direct DB access
- Remove InventoryItems DbSet from AppDbContext (inventory data now in microservice)
- Remove inventory seed data from monolith (managed by microservice)
- Remove Product.Inventory navigation property
- Convert InventoryItem model to DTO for HTTP response deserialization
- Add InventoryService:BaseUrl configuration in appsettings.json
- Update tests with Moq-based HTTP client mocking
- All 3 tests pass
@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

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