Skip to content

refactor: Replace in-process Inventory calls with HTTP client to inventory-service#251

Open
devin-ai-integration[bot] wants to merge 10 commits intodevin/1773358765-initial-monolithfrom
workshop-mason-1775484269
Open

refactor: Replace in-process Inventory calls with HTTP client to inventory-service#251
devin-ai-integration[bot] wants to merge 10 commits intodevin/1773358765-initial-monolithfrom
workshop-mason-1775484269

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot commented Apr 6, 2026

Summary

Decouples the Inventory module from the OrderManager monolith by replacing direct EF Core database access (InventoryService) with HTTP calls to the new standalone inventory microservice (InventoryHttpClient).

Key changes:

  • Deleted InventoryService.cs (direct DB), InventoryItem.cs model, InventoryItems DbSet, seed data, and Product.Inventory navigation property
  • Deleted Clients/InventoryServiceClient.cs — removed dead duplicate HTTP client class
  • Added InventoryHttpClient (in Services/) — typed HTTP client calling the inventory microservice REST API for all inventory operations
  • Updated InventoryController to proxy through InventoryHttpClient
  • Updated OrderService.CreateOrderAsync to call DeductStockAsync over HTTP instead of mutating local InventoryItems (returns null on insufficient stock / 409)
  • Updated ProductService to remove .Include(p => p.Inventory) from all queries
  • Registered InventoryHttpClient via AddHttpClient<> in Program.cs with configurable InventoryService:BaseUrl (default http://localhost:5001)
  • Updated tests with MockHttpMessageHandler to simulate inventory-service responses

Updates since last revision

  • Removed dead Clients/InventoryServiceClient.cs and fixed namespace imports across InventoryController, OrderService, and Program.cs (were importing OrderManager.Api.Clients but class lives in OrderManager.Api.Services)
  • Removed CheckStockAsync and StockCheckResult — the inventory microservice has no /check endpoint. OrderService.CreateOrderAsync now calls DeductStockAsync directly; a null return (from 409 Conflict) means insufficient stock
  • Verified end-to-end integration locally: monolith on port 5000 + inventory-service on port 8080 — GET /api/inventory returns data from microservice, POST /api/orders deducts stock via HTTP, stock confirmed decremented on microservice

Review & Testing Checklist for Human

  • No compensation for multi-item order failures: CreateOrderAsync loops over items calling DeductStockAsync for each. If deduction succeeds for item N but fails for item N+1 (or if SaveChangesAsync fails after all deductions), previously deducted items are not rolled back on the microservice. The old code did this atomically in a single DB transaction. Evaluate whether this is acceptable for workshop scope or if a saga/compensation pattern is needed.
  • No HTTP resilience policies: No retry, circuit breaker, or fallback on InventoryHttpClient. If the inventory-service is unreachable, CreateOrderAsync throws unhandled HttpRequestException (raw 500 to client). The 30s timeout is the only safeguard. Consider adding Polly policies before production use.
  • InventoryController.Restock has no error handling: If the inventory-service returns an error, the raw HttpRequestException propagates as an unhandled 500. Other controller endpoints have the same issue.
  • End-to-end test: Start the inventory-service (port 8080 or configure InventoryService:BaseUrl) and the monolith on its default port. Verify: GET /api/inventory returns data, POST /api/orders deducts stock on the microservice, and ordering more than available stock returns a clear error (not an unhandled 500).

Notes

  • The InventoryItems table will remain in existing SQLite databases (no drop migration generated) but is no longer read or written by the monolith.
  • Test coverage is reduced: old tests verified actual inventory DB mutations; new tests only verify behavior against mocked HTTP responses. InventoryHttpClient methods are not virtual or behind an interface, making them harder to mock for unit testing.
  • The companion inventory microservice PR is app_dotnet-angular-microservices PR #8 on the workshop-mason branch.

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

bsmitches and others added 8 commits March 12, 2026 19:17
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ntory-service

- Add InventoryHttpClient that calls the new inventory-service via HTTP
- Update InventoryController to use InventoryHttpClient instead of InventoryService
- Update OrderService to deduct stock via HTTP client instead of direct DB access
- Register InventoryHttpClient with HttpClientFactory in Program.cs
- Add InventoryService:BaseUrl configuration to appsettings.json
- Remove direct dependency on InventoryService for inventory operations
…service

- Add InventoryHttpClient for REST calls to standalone inventory microservice
- Update InventoryController to delegate to InventoryHttpClient
- Update OrderService to check/deduct stock via HTTP instead of direct DB
- Remove InventoryItem model and InventoryService (now in microservice)
- Remove InventoryItems DbSet from AppDbContext
- Remove inventory seeding from SeedData (owned by microservice)
- Remove Product.Inventory navigation property
- Update ProductService to remove Inventory includes
- Add InventoryService:BaseUrl config in appsettings.json
- Update tests to use mock HTTP handler for InventoryHttpClient
…ntory microservice

- Add InventoryServiceClient HTTP client for communicating with standalone inventory-service
- Refactor InventoryController to proxy requests through HTTP client
- Refactor OrderService.CreateOrderAsync to use HTTP client for stock check/deduction
- Register HttpClient<InventoryServiceClient> in DI with configurable base URL
- Add InventoryService:BaseUrl configuration in appsettings.json
- Update tests to use new OrderService constructor with InventoryServiceClient
- Remove direct InventoryService dependency (in-process DB calls)
@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.

1 participant