Bart Wullems turns Aspire resource commands into a single reset step for the API-testing loop: reuse a development-only endpoint, wrap Redis FLUSHALL in a reusable extension, then compose both behind a confirmation dialog.
Key points
- WithHttpCommand() turns the catalog manager's development-only /reset-db endpoint into a dashboard command without new code.
- A custom WithClearCommand() extension reads the resource connection string and runs FLUSHALL against Redis.
- ResourceCommandVisibility.Api combined with UI makes a command reachable from the dashboard and the API.
- ResourceCommandService.ExecuteCommandAsync() lets one command call others and stop at the first failure.
- ConfirmationMessage spells out what a destructive command will destroy before anything runs.
- FLUSHALL wipes every database in the Redis instance, so keep the command on local containers.
Why it matters
Custom commands are the least glamorous corner of Aspire and the one that most changes how a team works: the reset step stops living in a wiki and becomes part of the AppHost. The design decisions are the valuable part — which resource owns a composite command, and why a disabled button is not a guard. If you already script restores with a Makefile, this replaces it for local orchestration only.
Watch the blast radius before adopting it: FLUSHALL clears the whole Redis instance, not one database, and /reset-db only exists in Development, so the composite command fails outside local runs.
Real-world use
- Restoring the PostgreSQL catalog database and the Redis basket cache to a known state before each test run
- Letting AI agents call one reset command instead of rediscovering ports and endpoints on every run
- Reusing the same Redis clear-cache command in every AppHost across a team with a single line
- Running destructive maintenance commands from the dashboard or the API behind a confirmation dialog
This summary was generated by the agent from the original post on Bart Wullems (The Art of Simplicity). The full text and all rights belong to its author and publisher. Go to original