ADR: A request is a query or a command
Status: accepted, 2026-10-23, at 1.0.4.39. Every request the API answers is a record named <Verb><Noun>Query or <Verb><Noun>Command, with exactly one handler that implements IQueryHandler or ICommandHandler. A query handler is handed reading ports only. Nothing in the Application ring is named *Service. CqrsTests fails the build when any of that stops being true.
Reading list
- Martin Fowler, CQRS (2011): one model to update and another to read, and his warning that for most systems the full pattern adds risky complexity. Read 2026-10-23.
- Microsoft Learn, CQRS pattern (updated 2025-02-21): the basic form keeps one store, and separate stores, events and eventual consistency are the advanced form with their own costs. Read 2026-10-23.
- Greg Young, CQRS Documents: CQRS as Meyer's command-query separation lifted from methods to objects, with event sourcing a pairing and never a requirement. Read 2026-10-23.
- Jimmy Bogard, Vertical Slice Architecture (2018): organise by request, and the request is already a command or a query. Read 2026-10-23.
- ADR: The onion cut into vertical slices and ADR: Onion and SOLID: the slices and the rings this record adds a rule inside.
- CQRS, the practices: the same decision as a page to learn from, with the counts this build has.
In plain words
Every request to this site either asks a question or asks for something to change. Asking which vehicles are live is a question. Placing a bid is a change. From this version the code says which one each request is, in its name, and the build refuses a question that has been handed the means to change anything.
That is the whole of it here. There is one database per store, as before, and no queue or bus between the two halves. The value is that a reader can tell from one word whether a piece of code can change anything, and a test holds that word to be true.
Context
Measured at 1.0.4.38: 27 handlers in the Application ring, each a sealed class <Verb><Noun>Handler with a HandleAsync, and no type named *Query or *Command. A handler's request was a loose list of arguments or a record with a free name (PlaceBid, VehicleSearch, BlogOpen). Beside the handlers sat three services and the class that composed them: BidService in four files placed bids, reset them and read standings; InventoryService in five files was reads only; MarketService ran the simulated room; and Auction held all three, so every bid and vehicle handler took Auction and could reach every write any of them had.
The ports had the same shape. IBlogStore, IAccountStore and ILinkOpens each carried the reads and the writes in one interface, so the query that lists blog posts was handed the method that saves one.
Decision
- Two interfaces in
api/TheYard.Application/Shared/Requests.cs, and nothing else is added: no bus, no mediator, no pipeline. A slice's Module maps its route to its handler, as it did.
public interface IQueryHandler<in TQuery, TResult>
{
Task<TResult> HandleAsync(TQuery query, CancellationToken cancellation);
}
public interface ICommandHandler<in TCommand, TResult>
{
Task<TResult> HandleAsync(TCommand command, CancellationToken cancellation);
}
Live from api/TheYard.Application/Shared/Requests.cs, region requests, read from this build at 99df7a8.
- Every request is a sealed record in its slice's Application folder, named
<Verb><Noun>Query when it reads and <Verb><Noun>Command when it changes something, and its handler is named the same with Handler in place of the last word. A request with nothing to say is an empty record (ReadFacetsQuery, ListPostsQuery) rather than a missing one, so every handler has the same shape.
- A query handler's constructor takes no parameter whose type ends in
Store or Writer. A command handler may take both sides.
- A port that a query needs only half of is split: the reading side is an interface ending in
Reader or Catalogue, and the writing side extends it or stands beside it. IBlogStore : IBlogReader, IAccountStore : IAccountReader and ILinkOpens : ILinkOpensReader in this version.
- The three services and
Auction go. Each store's auction is three parts, each implementing a reading and a writing interface (api/TheYard.Application/Shared/Auction/AuctionParts.cs): Stock (the catalogue, read only, so IStockReader alone), BidBook (IBidReader, IBidWriter) and Room (IRoomReader, IRoomWriter). StandingReader lays the three reading sides over each other in the one order the rules need, and is the only way a query reads a vehicle. The round of the room and a buyer's start-over move into their command handlers.
- Nothing in the Application ring's root or its slices is named
*Service.
One query, the three the catalogue answers, each taking the reading side only:
public sealed class SearchVehiclesHandler(StandingReader standings) : IQueryHandler<SearchVehiclesQuery, StandingPage>
{
public Task<StandingPage> HandleAsync(SearchVehiclesQuery request, CancellationToken cancellation) =>
standings.SearchAsync(request.Filter, request.Clock, request.Sort, request.Limit, request.Offset, cancellation);
}
public sealed class ReadFacetsHandler(IStockReader inventory) : IQueryHandler<ReadFacetsQuery, InventoryFacets>
{
public Task<InventoryFacets> HandleAsync(ReadFacetsQuery query, CancellationToken cancellation) => inventory.FacetsAsync(cancellation);
}
public sealed record ReadFacetsQuery;
public sealed class FindVehicleHandler(StandingReader standings, Func<AuctionClock> clock) : IQueryHandler<FindVehicleQuery, FoundVehicle>
{
public async Task<FoundVehicle> HandleAsync(FindVehicleQuery query, CancellationToken cancellation) =>
new(await standings.FindAsync(query.Id, cancellation), clock());
}
public sealed record FindVehicleQuery(string Id);
Live from api/TheYard.Application/Features/Vehicles/VehicleHandlers.cs, region vehicle-handlers, read from this build at 99df7a8.
One command, the bid, which reads the vehicle as it stands and writes through the bids' writing side:
public sealed class PlaceBidHandler(StandingReader standings, IBidWriter bids, Func<AuctionClock> clock) : ICommandHandler<PlaceBidCommand, BidAnswer>
{
public async Task<BidAnswer> HandleAsync(PlaceBidCommand request, CancellationToken cancellation)
{
if (!request.SessionOnThisStore)
{
return BidAnswer.Refused(BidAnswerKind.SessionElsewhere, null);
}
var now = clock();
cancellation.ThrowIfCancellationRequested();
if (await standings.FindAsync(request.VehicleId, cancellation) is not { } vehicle)
{
return BidAnswer.Refused(BidAnswerKind.NoSuchVehicle, null);
}
var outcome = request.Amount is { } amount
? await bids.PlaceBidAsync(vehicle.Vehicle, amount, now, request.UserId, cancellation)
: await bids.BuyNowAsync(vehicle.Vehicle, now, request.UserId, cancellation);
if (outcome.Kind == BidOutcomeKind.Rejected)
{
return BidAnswer.Refused(BidAnswerKind.Rejected, outcome.Reason);
}
return new BidAnswer(
BidAnswerKind.Placed,
outcome,
null,
standings.BidsOf(request.UserId).TryGetValue(request.VehicleId, out var standing) ? standing : null,
await standings.FindAsync(request.VehicleId, CancellationToken.None) ?? vehicle,
now);
}
}
Live from api/TheYard.Application/Features/Bids/PlaceBidHandler.cs, region place-bid, read from this build at 99df7a8.
The three parts and their two sides:
public interface IStockReader
{
Task<Vehicle?> FindAsync(string id, CancellationToken cancellation);
Task<IReadOnlyList<Vehicle>> FindManyAsync(IReadOnlyCollection<string> ids, CancellationToken cancellation);
Task<IReadOnlyList<Vehicle>> FirstLiveAsync(AuctionClock clock, int take, CancellationToken cancellation);
Task<InventoryFacets> FacetsAsync(CancellationToken cancellation);
Task<SearchResult> SearchAsync(VehicleFilter filter, AuctionClock clock, VehicleSort sort = VehicleSort.EndingSoonest, int limit = int.MaxValue, int offset = 0, ListingOverlay? overlay = null, CancellationToken cancellation = default);
}
public interface IBidReader
{
bool IsEmpty { get; }
IReadOnlyDictionary<string, BidState> SnapshotFor(string userId);
IReadOnlyDictionary<string, VehicleStanding> Standing();
bool IsSold(string vehicleId);
IReadOnlyDictionary<string, BidState> StandingAsBids();
Vehicle Apply(Vehicle vehicle);
}
public interface IBidWriter
{
Task<BidOutcome> PlaceBidAsync(Vehicle vehicle, int amount, AuctionClock clock, string userId, CancellationToken cancellation);
Task<BidOutcome> BuyNowAsync(Vehicle vehicle, AuctionClock clock, string userId, CancellationToken cancellation);
Task<IReadOnlyList<string>> ResetAsync(string userId, CancellationToken cancellation);
}
public interface IRoomReader
{
bool IsEmpty { get; }
IReadOnlyDictionary<string, MarketBid> Snapshot();
Vehicle Apply(Vehicle vehicle);
}
public interface IRoomWriter
{
IReadOnlyList<string> Tick(IReadOnlyList<Vehicle> candidates, IReadOnlyDictionary<string, BidState> buyerBids, AuctionClock clock, int maxBids = 3);
void Forget(IEnumerable<string> vehicleIds);
}
Live from api/TheYard.Application/Shared/Auction/AuctionParts.cs, region auction-parts, read from this build at 99df7a8.
What holds it
CqrsTests, new, red on 1.0.4.38 with only its file applied:
public sealed class CqrsTests(WebApplicationFactory<Program> factory) : IClassFixture<WebApplicationFactory<Program>>
{
private static readonly Assembly Application = typeof(IQueryHandler<,>).Assembly;
private const string Features = "TheYard.Application.Features";
private static List<Type> Requests(string word) =>
[.. Application.GetTypes().Where(type => type.IsClass && type.Namespace?.StartsWith(Features, StringComparison.Ordinal) == true && type.Name.EndsWith(word, StringComparison.Ordinal))];
private static List<string> Services() =>
[.. Application.GetTypes()
.Where(type => type.IsClass && !type.Name.StartsWith('<') && type.Name.EndsWith("Service", StringComparison.Ordinal)
&& (type.Namespace == "TheYard.Application" || type.Namespace?.StartsWith(Features, StringComparison.Ordinal) == true))
.Select(type => type.Name)];
private static List<Type> HandlerTypes() =>
[.. Application.GetTypes().Where(type => type.IsClass && !type.IsAbstract && type.Name.EndsWith("Handler", StringComparison.Ordinal) && type.Namespace?.StartsWith(Features, StringComparison.Ordinal) == true)];
private static List<(Type Contract, Type Request, bool Query)> Contracts(Type handler) =>
[.. handler.GetInterfaces()
.Where(contract => contract.IsGenericType && (contract.GetGenericTypeDefinition() == typeof(IQueryHandler<,>) || contract.GetGenericTypeDefinition() == typeof(ICommandHandler<,>)))
.Select(contract => (contract, contract.GetGenericArguments()[0], contract.GetGenericTypeDefinition() == typeof(IQueryHandler<,>)))];
[Fact]
public void Every_handler_is_exactly_one_query_or_command_handler_named_for_its_request()
{
var handlers = HandlerTypes();
Assert.True(handlers.Count >= 27, $"only {handlers.Count} handlers were found");
var wrong = new List<string>();
foreach (var handler in handlers)
{
var contracts = Contracts(handler);
if (contracts.Count != 1)
{
wrong.Add($"{handler.Name} implements {contracts.Count} of IQueryHandler and ICommandHandler; it implements exactly one");
continue;
}
var (_, request, query) = contracts[0];
string expected = handler.Name[..^"Handler".Length] + (query ? "Query" : "Command");
if (request.Name != expected)
{
wrong.Add($"{handler.Name} handles {request.Name}; its request is named {expected}");
}
}
Assert.True(wrong.Count == 0, string.Join(Environment.NewLine, wrong));
}
[Fact]
public void Every_query_and_command_has_exactly_one_handler()
{
var requests = Requests("Query").Concat(Requests("Command")).ToList();
Assert.True(requests.Count >= 27, $"only {requests.Count} requests were found");
var handled = HandlerTypes().SelectMany(Contracts).GroupBy(contract => contract.Request).ToDictionary(group => group.Key, group => group.ToList());
var wrong = new List<string>();
foreach (var request in requests)
{
int count = handled.TryGetValue(request, out var found) ? found.Count : 0;
if (count != 1)
{
wrong.Add($"{request.Name} has {count} handlers; it has exactly one");
}
else if (request.Name.EndsWith("Query", StringComparison.Ordinal) != found![0].Query)
{
wrong.Add($"{request.Name} is handled as a {(found[0].Query ? "query" : "command")}; its name says otherwise");
}
if (!request.IsSealed)
{
wrong.Add($"{request.Name} is not sealed");
}
}
Assert.True(wrong.Count == 0, string.Join(Environment.NewLine, wrong));
}
[Fact]
public void A_query_handler_is_handed_no_store_and_no_writer()
{
static string Bare(Type type) => (Nullable.GetUnderlyingType(type) ?? type).Name;
var wrong = HandlerTypes()
.Where(handler => Contracts(handler).Any(contract => contract.Query))
.SelectMany(handler => handler.GetConstructors().SelectMany(constructor => constructor.GetParameters())
.Where(parameter => Bare(parameter.ParameterType).EndsWith("Store", StringComparison.Ordinal) || Bare(parameter.ParameterType).EndsWith("Writer", StringComparison.Ordinal))
.Select(parameter => $"{handler.Name} takes {Bare(parameter.ParameterType)} {parameter.Name}; a query takes the reader"))
.ToList();
Assert.True(wrong.Count == 0, string.Join(Environment.NewLine, wrong));
}
[Fact]
public void A_query_handler_is_handed_no_port_that_can_write()
{
var wrong = HandlerTypes()
.Where(handler => Contracts(handler).Any(contract => contract.Query))
.SelectMany(handler => handler.GetConstructors().SelectMany(constructor => constructor.GetParameters())
.Select(parameter => (handler, parameter, writes: WritingMembers(Nullable.GetUnderlyingType(parameter.ParameterType) ?? parameter.ParameterType)))
.Where(found => found.writes.Count > 0)
.Select(found => $"{found.handler.Name} takes {found.parameter.ParameterType.Name} {found.parameter.Name}, which can {string.Join(", ", found.writes)}; a query takes a port that only reads"))
.Where(line => !ExemptReaders.Any(exempt => line.StartsWith(exempt.Key + " ", StringComparison.Ordinal)))
.ToList();
Assert.True(wrong.Count == 0, string.Join(Environment.NewLine, wrong));
}
private static readonly Regex WritingVerb = new(@"^(Keep|Write|Save|Upsert|Delete|Add|Remove|Record|Put|Set)(?=[A-Z_]|$)", RegexOptions.Compiled);
private static readonly Dictionary<string, string> ExemptReaders = new(StringComparer.Ordinal);
private static List<string> WritingMembers(Type port)
{
if (port.Namespace?.StartsWith("TheYard.", StringComparison.Ordinal) != true)
{
return [];
}
IEnumerable<Type> contracts = port.IsInterface ? port.GetInterfaces().Prepend(port) : [port];
return [.. contracts
.SelectMany(contract => contract.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly))
.Where(member => member is not MethodInfo { IsSpecialName: true } && WritingVerb.IsMatch(member.Name))
.Select(member => member.Name)
.Distinct(StringComparer.Ordinal)
.Order(StringComparer.Ordinal)];
}
[Fact]
public void No_type_in_the_Application_ring_s_slices_or_root_is_a_service()
{
var services = Services();
Assert.True(services.Count == 0, "types named *Service: " + string.Join(", ", services));
}
[Fact]
public void Every_route_that_asks_a_handler_asks_a_query_or_a_command_handler()
{
var routes = factory.Services.GetRequiredService<EndpointDataSource>().Endpoints.OfType<RouteEndpoint>()
.Select(endpoint => endpoint.Metadata.GetMetadata<MethodInfo>())
.OfType<MethodInfo>()
.Where(answer => answer.DeclaringType?.Namespace?.StartsWith("TheYard.Api.Features.", StringComparison.Ordinal) == true)
.ToList();
Assert.NotEmpty(routes);
var wrong = routes
.SelectMany(answer => answer.GetParameters()
.Where(parameter => parameter.ParameterType.Namespace?.StartsWith(Features, StringComparison.Ordinal) == true && parameter.ParameterType.Name.EndsWith("Handler", StringComparison.Ordinal))
.Where(parameter => Contracts(parameter.ParameterType).Count != 1)
.Select(parameter => $"{answer.DeclaringType!.Name}.{answer.Name} asks {parameter.ParameterType.Name}, which is not a query or a command handler"))
.ToList();
Assert.True(wrong.Count == 0, string.Join(Environment.NewLine, wrong));
}
[Fact]
public void The_practices_page_quotes_the_counts_this_build_has()
{
string page = File.ReadAllText(Path.Combine(Repo.Root(), "docs", "best-practices", "CQRS.md"));
var counted = new Dictionary<string, int>(StringComparer.Ordinal)
{
["queries"] = Requests("Query").Count,
["commands"] = Requests("Command").Count,
["handlers"] = HandlerTypes().Count,
["services"] = Services().Count,
};
var wrong = new List<string>();
foreach (var (shape, actual) in counted)
{
var quoted = Regex.Match(page, $@"^\| {shape} \| (\d+) \|", RegexOptions.Multiline);
if (!quoted.Success)
{
wrong.Add($"docs/best-practices/CQRS.md has no row for {shape}");
}
else if (int.Parse(quoted.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture) != actual)
{
wrong.Add($"docs/best-practices/CQRS.md says {quoted.Groups[1].Value} {shape} and this build has {actual}");
}
}
Assert.True(wrong.Count == 0, string.Join(Environment.NewLine, wrong));
}
}
Live from api/TheYard.Tests/CqrsTests.cs, region cqrs-tests, read from this build at 99df7a8.
- every handler implements exactly one of the two interfaces and is named for its request;
- every
*Query and *Command under Features/ has exactly one handler, is sealed, and is handled as what its name says;
- a query handler is handed no store and no writer;
- no type in the Application ring's root or its slices is named
*Service;
- every route that asks a handler asks a query or a command handler, beside
HandlerRuleTests, which holds a ruled route to one handler;
- the counts on CQRS, the practices are this build's.
HandlerRuleTests.Every_handler_is_tested_with_fakes_and_no_host covers the renamed handlers unchanged: each is still built in a test with fakes at its ports and no host.
What was considered
MediatR, or a hand-written dispatcher. Rejected: it puts a lookup between the route and the code it runs, so "go to definition" on a route lands on an interface. The Module already maps one route to one handler and the compiler checks it; a bus would add a moving part to say what the map says now.
A second store for reads, or events between the halves. Rejected for this codebase. The catalogue is one hundred thousand rows a page at a time, read by the store that holds it (ADR: The store does the work), and both stores answer a page inside the budget the site already keeps. Microsoft's own page names the cost: two stores that must be kept in step, and a read side that can be behind. Nothing here is slow enough to buy that.
Keeping the services and naming their methods as queries and commands. Rejected: the point of the split is what a handler can reach. A query handed Auction could place a bid whatever its name said; a query handed StandingReader cannot.
Moving every line of BidService into the three bid handlers. Rejected for this version: the book of bids is one instance per store that the bid, the reset, the room and every listing share, with a gate and a replay from the store at startup. Its body moved whole and its two sides are now interfaces; cutting it by job is the 300-line rule's rung (ADR-088's addendum of that version).
Consequences
Every handler and its request were renamed, so the diff is wide and shallow: 27 records added, 27 handlers renamed or re-typed, the route bodies changed only in the record they build. The three services' files were renamed (BidService*.cs to BidBook*.cs, InventoryService*.cs to Stock*.cs, MarketService.cs to Room.cs), and every live fence and link that named them was repointed; prose in older records that names them was left as written. Auction.cs is gone; its two regions that records quote, overlays and views, live in StandingReader.cs under the same names. The handler tests build each handler over the three parts the way the slices' Modules do.
What this does not do: the 24 Admin reads that HandlerRuleTests still names as exempt ask no handler yet. They become queries in the next version (ADR-075's row for this record says so), and from then every route is one of the two.
Where it sits
Application ring only, and the host's Modules that build the handlers. Single responsibility: ADR-107 says what a slice is and ADR-114 where a file lives; this record says what a request is. What would change it: a read that the store holding the writes cannot answer in time, which is the case Microsoft's page gives for a second store.
Addendum, 2026-10-23 (1.0.4.43): the Admin tab's 24 reads are queries
The record's first version left the Admin tab's reads asking no handler, named as exempt in HandlerRuleTests. From 1.0.4.43 each is a query or a command with one handler: 21 queries (the SQL, store and log rings, the timings, the kept rings, the activity report, the visitor rows, the kept log, the machines, memory against traffic, Azure's view of this container, the peer, the telemetry, the arrival, the store bar, the page sweep, the gate's counts and its file, the proof's status, the costs, and a served document) and three commands (start the page sweep, start the proof, run the partition key experiment), in Application/Features/Admin/Operations, Proof, Admin/Costs and Docs. Each handler takes a port split by what it reads (IRingReadings, IActivityReadings, IMachineReadings, IAzureReadings, IEvidenceReadings and the rest), answered by the host part that holds the data (OperationsReadings.cs, MachineCardReadings.cs, DocumentReadings.cs): the bodies are the routes' bodies, moved, so every card reads what it read before. What a route decided in its body, a handler decides now: the window, the card and the kind it can read, and what to say when there is nothing; the answer is one Reading the route turns into its status. The operator's key and whether the visitor rows are served stay checks the route makes before it asks (AdminSettings joins AdminKey beside the handlers).
AdminQueryTests builds all 24 handlers over one fake at every port with no host, and AdminQueryRouteTests holds the store bar's 200, the gate's counts' 200 and 404 and a document's 200 and 404 through the real host. Reading, the answer every one of these handlers gives, is in the Application ring's Shared/ folder, because the operations, the costs, the proof and the documents all answer with it and rule 1 of the slices keeps one slice out of another's folder. Steve's ruling of 11:37 that day was the reason: the Foreman reads exactly these routes, and a read with no handler has no fake to test against.
Still exempt, each with its reason in HandlerRuleTests: fifteen routes where the host serves its own files (the pictures, the drawings, the Bicep, the resume, the about page, the recommendations), its health and version, the pulse, and its error rings. They are not reads of the business or of the Admin cards, and they stay where they are until a lane gives them a reason to be queries.
Addendum, 2026-10-25 (1.0.4.68): a reader port is known by what it can do
The rule that keeps a store out of a query read the port's name: a parameter type ending in Store or Writer was red. A port named "...Reader" that wrote passed. From this version CqrsTests.A_query_handler_is_handed_no_port_that_can_write reads the port itself: no type a query handler takes by constructor, among this codebase's own, has a member, counting every member of every interface it inherits, whose name starts with Keep, Write, Save, Upsert, Delete, Add, Remove, Record, Put or Set. The name check stays beside it.
It was green on 1.0.4.67 with only its file applied, and that green is the finding: the ports the queries take were already split, the visitors' reader from its store (IVisitorReader under IVisitorStore) and the blog's reader from its store among them. To prove it can fail, a writing member planted on IVisitorReader turned it red at once ("ReadPeopleCountHandler takes IVisitorReader visitors, which can KeepProbeAsync"). The test carries an exemption list, empty, that only shrinks. docs/best-practices/CQRS.md says how the rule reads a port.
[Fact]
public void A_query_handler_is_handed_no_port_that_can_write()
{
var wrong = HandlerTypes()
.Where(handler => Contracts(handler).Any(contract => contract.Query))
.SelectMany(handler => handler.GetConstructors().SelectMany(constructor => constructor.GetParameters())
.Select(parameter => (handler, parameter, writes: WritingMembers(Nullable.GetUnderlyingType(parameter.ParameterType) ?? parameter.ParameterType)))
.Where(found => found.writes.Count > 0)
.Select(found => $"{found.handler.Name} takes {found.parameter.ParameterType.Name} {found.parameter.Name}, which can {string.Join(", ", found.writes)}; a query takes a port that only reads"))
.Where(line => !ExemptReaders.Any(exempt => line.StartsWith(exempt.Key + " ", StringComparison.Ordinal)))
.ToList();
Assert.True(wrong.Count == 0, string.Join(Environment.NewLine, wrong));
}
private static readonly Regex WritingVerb = new(@"^(Keep|Write|Save|Upsert|Delete|Add|Remove|Record|Put|Set)(?=[A-Z_]|$)", RegexOptions.Compiled);
private static readonly Dictionary<string, string> ExemptReaders = new(StringComparer.Ordinal);
private static List<string> WritingMembers(Type port)
{
if (port.Namespace?.StartsWith("TheYard.", StringComparison.Ordinal) != true)
{
return [];
}
IEnumerable<Type> contracts = port.IsInterface ? port.GetInterfaces().Prepend(port) : [port];
return [.. contracts
.SelectMany(contract => contract.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly))
.Where(member => member is not MethodInfo { IsSpecialName: true } && WritingVerb.IsMatch(member.Name))
.Select(member => member.Name)
.Distinct(StringComparer.Ordinal)
.Order(StringComparer.Ordinal)];
}
Live from api/TheYard.Tests/CqrsTests.cs, region a-reader-is-known-by-what-it-can-do, read from this build at 99df7a8.
Addendum, 2026-10-25 (1.0.4.75): what CQRS means in the job hunt's Function
The Function answers no request. Its timers each run one use case on a clock, so there is no request record to name ...Query or ...Command and no handler to count, and this record's naming rule does not carry over. The half that does carry over is the one that matters: a use case that only reads cannot write.
- The ports are split.
IMergeStore (the job-hunt share) extends IShareReader (exists, read, list), and IInbox extends IInboxReader (find, read, the thread's senders and draft); the archive and the share's writes are on the extending halves only.
- The reading use cases take the reading halves.
InboxTriage (the triage window) takes IShareReader and IInboxReader; MergerHealth.ReadAsync takes IShareReader.
- Nothing is a service in any of the three rings.
The Function's CqrsTests holds all three, reading a port by what it can do with the same writing-verb rule the site's queries are held to (the addendum of 1.0.4.68), widened by the Function's own verbs (Append, Move, Replace, Ensure, Archive, Mark, Block). It was red with the split reverted: "InboxTriage takes IMergeStore store, which can AppendAsync, EnsureFolderAsync, MoveAsync, ReplaceAsync, WriteAsync" and "InboxTriage takes IInbox inbox, which can ArchiveAsync".
Addendum, 2026-10-30 (1.0.4.127): the Function's read-only use cases are found, not listed
The addendum above is still the rule. What changed is its subject. It named two use cases,
InboxTriage and MergerHealth, and the Function's CqrsTests held exactly those two to reading
ports through a dictionary kept by hand. So the rule was as good as somebody's memory: a use case
written next week that reads the share and is handed IMergeStore rather than IShareReader would
never be asked the question, because it would not be in the dictionary. A rule whose subject is a
list only ever covers the list, and this list had not grown in the month since it was written.
The dictionary is gone. tests/rules/UseCaseRule.cs reads the Application ring for every type handed
a port and asks the compiled code which of them write; the rule runs over the ones that do not. It
finds the same two, and that is the result worth recording: the number did not change, the way of
arriving at it did, and the next read-only use case is covered the day it is written rather than the
day somebody remembers it.
Proved both ways, with one plant
A read-only use case handed the writing half of the share's port was planted under
Features/Triage/: TriageBacklog(IMergeStore store), which lists the triage folder, asks whether
seen.tsv is there, and does nothing else.
- The hand-kept test passed, 3 of 3, with the plant in the tree. That is the defect, not a
surprise: it iterates its dictionary, and
TriageBacklog is not in it.
- Discovery failed on the same tree: "TriageBacklog only reads and takes IMergeStore store by its
constructor, which can AppendAsync, EnsureFolderAsync, MoveAsync, ReplaceAsync, WriteAsync; a use
case that only reads takes the reading half".
What "writes" means, and the near-miss that would have shipped a false red
Whether a use case writes is read from its compiled code and never from its name, because a name is a
promise and nothing checks a promise. A use case writes when the code it owns reaches a call to a
member whose name starts with a writing verb on one of its family's types. Reaches is the whole
difficulty, and two hops are invisible to a scan of one method body.
The first is the state machine. An async method's own body is builder plumbing; the calls a
reader sees in the source live in the MoveNext of a nested compiler-generated type that the builder
starts generically, so no call instruction joins the two. The edge is taken from
AsyncStateMachineAttribute, which names that type.
The second is delegation, and it is the one that nearly shipped. Measured one method deep, the
first run of the discovery read TrackerMerger as a use case that only reads while holding
IMergeStore - this rule's own failure message, aimed at the type whose entire job is writing.
TrackerMerger calls nothing that writes: it makes a MergeContext and the merge steps and lets them
write. It was caught by reading the whole printed list by eye rather than its total, which is what
ADR-122's addendum of 1.0.4.125 asks of a rung, and it was caught before a line of the rule was
written. So a write now travels backwards along every call a method makes.
The walk is over methods and not types, deliberately. Collapsed to types, MergerHealth would
read as a writer for calling TrackerMerger.IsSpoolFile, a static that tests a file name.
What is a port, and the two limits left in place
A port is one of the family's interfaces, or one of its classes that is not a record - which is how
MergeContext, a class holding the share's writing half behind two safe ways to change the master, is
a port and is read as a writer. A record is never a port: its compiler-generated equality takes
its own type, so every record in the ring would read as a type handed one of the family's types, and
twenty-two of them did on the first measurement.
Two limits are named rather than quietly fixed, because fixing a measurement inside the commit that
depends on it is the move ADR-122 exists to refuse:
TrackerFrame.Record matches the writing-verb pattern as the verb "record" where it is the noun,
the CSV record text. It cannot bite, because a record is never a port, but it is the same shape of
defect as the three ratchet numbers this lane has found mismeasuring.
- A write reached through a delegate is invisible. A port passed as a
Func<> or an action and
invoked there leaves no call instruction naming the member. Nothing in the Function does it, and the
one delegate in the ring is a clock.
The counts the build holds - eighteen use cases, two of them read-only - are read back out of
docs/best-practices/CQRS.md by the Function's own CqrsTests, so the page cannot go stale either.
Enforced by
3 rules in the rulebook cite this record, each held by a test on every release.