feat: connect Catalog to Basket with direct C# basket previews - #8
Open
ivanmilevtues wants to merge 2 commits into
Open
ivanmilevtues wants to merge 2 commits into
ivanmilevtues wants to merge 2 commits into
Conversation
Introduce a direct Basket-to-Catalog HTTP connection with Aspire service discovery. Validate complete batches before saving and preserve baskets on catalog failures. Cover missing products, outages, cancellation, authentication and input limits. Amp-Thread-ID: https://ampcode.com/threads/T-01a0d851-f6a1-75de-9f3b-578690b1f00f Co-authored-by: Amp <amp@ampcode.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
CodeBoarding reviewStatus: 5 changed components See the full change in CodeBoarding. graph LR
n_Client_App["Client App"]
n_Ordering_Service["Ordering Service"]
n_Identity_API["Identity API"]
n_Web_Frontends["Web Frontends"]
n_Catalog_Service["Catalog Service"]
n_Webhooks_and_Shared_Infrastructure["Webhooks and Shared Infrastructure"]
n_Event_Bus["Event Bus"]
n_Basket_API["Basket API"]
n_Application_Host_and_Defaults["Application Host and Defaults"]
n_Payment_Processor["Payment Processor"]
n_Payment_Processor -- "publishes events to" --> n_Event_Bus
n_Ordering_Service -- "stores outbox events in" --> n_Catalog_Service
n_Ordering_Service -- "uses migration helpers in" --> n_Webhooks_and_Shared_Infrastructure
n_Ordering_Service -- "publishes and subscribes events via" --> n_Event_Bus
n_Ordering_Service -- "configures defaults from" --> n_Application_Host_and_Defaults
n_Web_Frontends -- "subscribes to events on" --> n_Event_Bus
n_Web_Frontends -- "configures HTTP and config defaults from" --> n_Application_Host_and_Defaults
n_Catalog_Service -- "uses migration helpers in" --> n_Webhooks_and_Shared_Infrastructure
n_Catalog_Service -- "publishes and subscribes events via" --> n_Event_Bus
n_Catalog_Service -- "calls" --> n_Basket_API
n_Webhooks_and_Shared_Infrastructure -- "subscribes to events on" --> n_Event_Bus
n_Webhooks_and_Shared_Infrastructure -- "configures authentication defaults from" --> n_Application_Host_and_Defaults
n_Event_Bus -- "dispatches events to" --> n_Payment_Processor
n_Event_Bus -- "dispatches events to" --> n_Ordering_Service
n_Event_Bus -- "dispatches events to" --> n_Web_Frontends
n_Event_Bus -- "dispatches events to" --> n_Catalog_Service
n_Event_Bus -- "dispatches events to" --> n_Webhooks_and_Shared_Infrastructure
n_Event_Bus -- "dispatches events to" --> n_Basket_API
n_Basket_API -- "subscribes to events on" --> n_Event_Bus
n_Basket_API -- "configures defaults from" --> n_Application_Host_and_Defaults
classDef added fill:#1f883d,stroke:#0b5d23,color:#ffffff;
classDef modified fill:#bf8700,stroke:#7d4e00,color:#ffffff;
classDef deleted fill:#cf222e,stroke:#82071e,color:#ffffff,stroke-dasharray:5 3;
class n_Catalog_Service,n_Basket_API modified;
linkStyle 9 stroke:#0b5d23,stroke-width:2px;
|
Catalog calls BasketPreview.Create in the Basket assembly without HTTP or the integration event bus. Keep previews read-only and reuse Basket validation. Preserve Catalog host settings when publishing the cross-service reference. Amp-Thread-ID: https://ampcode.com/threads/T-01a0d851-f6a1-75de-9f3b-578690b1f00f Co-authored-by: Amp <amp@ampcode.com>
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
Focused architecture demo with two new connections between Catalog and Basket. The headline change is now a direct C# Catalog Service → Basket API dependency, as requested, so static analysis has an explicit cross-component method call to follow.
Direct C# connection: read-only basket preview
Catalog loads the product and directly invokes Basket-owned validation/pricing code. This hop uses neither HTTP nor RabbitMQ. It reuses code inside the Catalog process; it does not contact the running Basket service, write a basket, reserve stock, or lock a price.
The preview can be invoked through Catalog's existing HTTP API surface:
It returns product ID/name, quantity, unit price, and total price. Quantity defaults to 1; invalid quantities return 400 with Basket's validation message; missing products return 404. Both Catalog API versions are supported and their generated OpenAPI documents are updated.
Deliberate demo tradeoff: Catalog references the Basket web-service assembly directly. That is build-time/code coupling, not independent microservice communication. A production design would normally extract reusable domain rules to a small library. Catalog's publish target excludes Basket host settings, and tests explicitly select the Catalog assembly to avoid the two generated
Programtypes.Existing first commit: Basket → Catalog HTTP validation
Kept from the initial iteration: authenticated Basket updates validate product IDs using Catalog's existing batch endpoint before saving. Missing products or failed lookups leave the stored basket unchanged. Empty-basket writes bypass Catalog. Input validation bounds the batch to 100 unique positive IDs/quantities; HTTP resilience, discovery, and AppHost wiring are included.
Demo walkthrough
CatalogApi.GetBasketPreview→BasketPreview.Create→BasketItem.Validate.Catalog.API.csproj→Basket.API.csprojproject reference. There is no event-bus handler or HTTP client on this preview path.aspire run, call the preview URL above using the Catalog endpoint from the dashboard. Changequantity=3toquantity=0to demonstrate Basket's validation. The caller-to-Catalog request is HTTP; the Catalog-to-Basket-code hop is an ordinary C# method call.Verification
dotnet test --solution eShop.Web.slnf: 158 passed, 0 failed, including container-backed functional tests.dotnet publish src/Catalog.API/Catalog.API.csproj: succeeds. Published/build configuration matches Catalog's own settings.git diff --check.Uses the pinned .NET SDK 10.0.302. Existing ASPIRE010 CLI-bundle warnings remain. No dependency upgrades, database migrations, generated CodeBoarding baseline edits, or UI changes. Based on the latest fetched
CodeBoarding/eShop:main.