Implement dependency injection for CLI commands - #114
Merged
Conversation
…IO for I/O management
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a DI-based composition root for the xping CLI so command implementations and I/O streams can be constructor-injected, improving modularity and testability while keeping the CLI’s stdout/stderr test seams intact.
Changes:
- Add a per-invocation
IHostcomposition root and resolve CLI commands from DI instead of static helpers/closures. - Introduce
ConsoleIOto carry per-invocationTextWriter/TextReaderthrough DI and aLocalRunStoreFactoryto createILocalRunStoreinstances with consistent logging wiring. - Update documentation references to the shared
XpingVersiontype and add the hosting dependency to the CLI project.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Xping.Sdk.Shared/XpingVersion.cs | Updates XML doc example to reference XpingVersion.Current. |
| src/Xping.Cli/Xping.Cli.csproj | Adds Microsoft.Extensions.Hosting to support HostApplicationBuilder DI composition. |
| src/Xping.Cli/Services/LocalRunStoreFactory.cs | Adds a factory abstraction to create ILocalRunStore instances per command invocation. |
| src/Xping.Cli/Program.cs | Builds/disposes an IHost per run and resolves command handlers via DI. |
| src/Xping.Cli/Hosting/ServiceCollectionExtensions.cs | Registers CLI services (I/O, store factory, commands) into DI. |
| src/Xping.Cli/Hosting/ConsoleIO.cs | Adds DI-carried per-invocation I/O streams for commands. |
| src/Xping.Cli/Commands/WhereCommand.cs | Converts to DI-resolved command with injected store factory + I/O. |
| src/Xping.Cli/Commands/ReportCommand.cs | Converts to DI-resolved command with injected store factory + I/O. |
| src/Xping.Cli/Commands/ClearCommand.cs | Converts to DI-resolved command with injected store factory + I/O. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
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.
Introduce a dependency injection framework for managing CLI commands and I/O operations, enhancing modularity and testability. This change includes the addition of a
ConsoleIOclass for I/O management and a factory for creatingILocalRunStoreinstances.