Parent
Closes part of #258 — Refactor AppHost MongoDB Dev Commands into WithMongoDbDevCommands Extension
What to build
Move the 120-line inline WithCommand block from AppHost.cs into a new MongoDbResourceBuilderExtensions static class in the same directory. The class exposes a single WithMongoDbDevCommands(databaseName) extension method on IResourceBuilder<MongoDBServerResource>.
The method owns the IsRunMode guard (caller invokes unconditionally), creates a shared SemaphoreSlim(1,1), and registers the existing clear-data command under the same name it has today. AppHost.cs shrinks from ~157 lines to ~30 lines with a single mongo.WithMongoDbDevCommands("myblog") call replacing the entire inline block.
The clear-data command behavior must be preserved exactly: non-blocking semaphore (WaitAsync(0)), connection-string resolution, skip system.* collections, DeleteManyAsync (preserves shells), per-collection try/catch with warnings, per-collection count in the result message, and the health-gate UpdateState callback. The namespace is Aspire.Hosting so no using is needed at the call site.
Acceptance criteria
Blocked by
None — can start immediately
Parent
Closes part of #258 — Refactor AppHost MongoDB Dev Commands into WithMongoDbDevCommands Extension
What to build
Move the 120-line inline
WithCommandblock fromAppHost.csinto a newMongoDbResourceBuilderExtensionsstatic class in the same directory. The class exposes a singleWithMongoDbDevCommands(databaseName)extension method onIResourceBuilder<MongoDBServerResource>.The method owns the
IsRunModeguard (caller invokes unconditionally), creates a sharedSemaphoreSlim(1,1), and registers the existing clear-data command under the same name it has today.AppHost.csshrinks from ~157 lines to ~30 lines with a singlemongo.WithMongoDbDevCommands("myblog")call replacing the entire inline block.The clear-data command behavior must be preserved exactly: non-blocking semaphore (
WaitAsync(0)), connection-string resolution, skipsystem.*collections,DeleteManyAsync(preserves shells), per-collection try/catch with warnings, per-collection count in the result message, and the health-gateUpdateStatecallback. The namespace isAspire.Hostingso nousingis needed at the call site.Acceptance criteria
src/AppHost/MongoDbResourceBuilderExtensions.csexists withinternal static class MongoDbResourceBuilderExtensionsin theAspire.HostingnamespaceWithMongoDbDevCommands(string databaseName)is the only public surface; inner methods (WithClearDatabaseCommand, etc.) are private helpersAppHost.cscontains a singlemongo.WithMongoDbDevCommands("myblog")call and no inline command logicIsRunModecheck lives inside the method — caller invokes unconditionallySemaphoreSlim(1,1)is created insideWithMongoDbDevCommandsand captured by the clear command closureMongoDbClearCommandTestsunit tests pass without modificationMongoClearDataIntegrationTestsintegration tests pass without modificationdotnet build) and no new warnings introducedBlocked by
None — can start immediately