Repository navigation
Document when to use Grand.Mediator; inject IGroupService into CustomerService - #1177
Merged
Merged
Conversation
added 2 commits
December 3, 2026 13:34
CustomerService reached GroupService through GetGroupBySystemNameQuery, whose handler only called IGroupService. There is no dependency cycle between the two services, so the mediator hop only hid a dependency. The query and its handler had no other caller and are removed.
The guidance said every write goes through a command, every read through a query, and controllers only call the mediator. The code does not work that way: business services are the business API, the admin panels use view-model services and define no request handlers, and the storefront uses queries for view models. Replace the rule with a table of where each host uses the mediator, and rules against a second entry point to the same operation.
List the reads named as commands, MaxOrderNumberCommand and the existing direct sends as exceptions; add rows for business queries, admin use-case commands and dedicated API queries; replace the examples with CancelOrderCommand, GetBlogPost and the current GetSuggestedProductsQuery; align constraints, fix-bug and explore-repository; comment the plugin boundary in DiscountService.
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.
Type: bugfix
Issue
The
.ai/guidance for agents said every write goes through a mediator command, every read through a query, and controllers only call_mediator.Send. The code does not work that way:I<Noun>Service) are the business API, and most writes go through them;I<Thing>ViewModelService;Grand.Web/Features, and some actions call a service directly.An agent following the old rule would add handlers where none belong, and a second way to reach operations that already have a service method.
In the code,
CustomerServicereachedGroupServicethroughGetGroupBySystemNameQuery, a handler that only calledIGroupService. The two services have no dependency cycle, so the mediator hop only hid a dependency.Solution
.ai/knowledge/architecture.md: the section "Grand.Mediator — when to use it" replaces the old rule. It has a table of where each host uses a service, a view-model service, a query, a command or a notification, plus short rules: one entry point per operation, queries have no side effects, no service-to-serviceSendwhen constructor injection works, and requests are not an extension point. Existing exceptions are listed so they are not copied.request-lifecycle.md,domain-events.md,constraints.md,naming.mdandprompts/implement-feature.mdare aligned with that section.CustomerServiceinjectsIGroupService.GetGroupBySystemNameQuery, its handler and its handler test are removed (no other caller).Breaking changes
GetGroupBySystemNameQuery(Grand.Business.Core.Queries.Customers) is removed. A plugin that sent it should callIGroupService.GetCustomerGroupBySystemNameinstead.CustomerServiceconstructor takesIGroupService. This matters only to code that constructs it by hand; DI resolves it automatically.Testing
dotnet test src/Tests/Grand.Business.Customers.Tests— 157 passed.dotnet test GrandNode.slnx— every project passes exceptGrand.Module.Api.Tests(4) andGrand.Business.Catalog.Tests(4). Those are inventory tests that share the Mongo test database during a parallel run. Run alone, both projects pass (144/144, 1232/1232).InsertGuestCustomer).