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
Open
Conversation
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)
…entory microservice
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:
|
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
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:
InventoryService.cs(direct DB),InventoryItem.csmodel,InventoryItemsDbSet, seed data, andProduct.Inventorynavigation propertyClients/InventoryServiceClient.cs— removed dead duplicate HTTP client classInventoryHttpClient(inServices/) — typed HTTP client calling the inventory microservice REST API for all inventory operationsInventoryControllerto proxy throughInventoryHttpClientOrderService.CreateOrderAsyncto callDeductStockAsyncover HTTP instead of mutating localInventoryItems(returns null on insufficient stock / 409)ProductServiceto remove.Include(p => p.Inventory)from all queriesInventoryHttpClientviaAddHttpClient<>inProgram.cswith configurableInventoryService:BaseUrl(defaulthttp://localhost:5001)MockHttpMessageHandlerto simulate inventory-service responsesUpdates since last revision
Clients/InventoryServiceClient.csand fixed namespace imports acrossInventoryController,OrderService, andProgram.cs(were importingOrderManager.Api.Clientsbut class lives inOrderManager.Api.Services)CheckStockAsyncandStockCheckResult— the inventory microservice has no/checkendpoint.OrderService.CreateOrderAsyncnow callsDeductStockAsyncdirectly; a null return (from 409 Conflict) means insufficient stockGET /api/inventoryreturns data from microservice,POST /api/ordersdeducts stock via HTTP, stock confirmed decremented on microserviceReview & Testing Checklist for Human
CreateOrderAsyncloops over items callingDeductStockAsyncfor each. If deduction succeeds for item N but fails for item N+1 (or ifSaveChangesAsyncfails 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.InventoryHttpClient. If the inventory-service is unreachable,CreateOrderAsyncthrows unhandledHttpRequestException(raw 500 to client). The 30s timeout is the only safeguard. Consider adding Polly policies before production use.InventoryController.Restockhas no error handling: If the inventory-service returns an error, the rawHttpRequestExceptionpropagates as an unhandled 500. Other controller endpoints have the same issue.InventoryService:BaseUrl) and the monolith on its default port. Verify:GET /api/inventoryreturns data,POST /api/ordersdeducts stock on the microservice, and ordering more than available stock returns a clear error (not an unhandled 500).Notes
InventoryItemstable will remain in existing SQLite databases (no drop migration generated) but is no longer read or written by the monolith.InventoryHttpClientmethods are notvirtualor behind an interface, making them harder to mock for unit testing.workshop-masonbranch.Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/26a7c9b49dfb4214b6f9e3970bc9abf3