AppConfig: Remove usage of ServiceProvider in ExecuteAsync.#1815
Open
conniey wants to merge 3 commits intomicrosoft:mainfrom
Open
AppConfig: Remove usage of ServiceProvider in ExecuteAsync.#1815conniey wants to merge 3 commits intomicrosoft:mainfrom
conniey wants to merge 3 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves testability for the AppConfig tool by removing command-time service resolution (CommandContext.ServiceProvider / context.GetService<T>()) and making IAppConfigService an explicit constructor dependency for the affected commands.
Changes:
- Updated AppConfig commands to inject
IAppConfigServicevia primary constructors and use the injected instance inExecuteAsync. - Updated AppConfig unit tests to construct commands with the injected
IAppConfigServicesubstitute and removed the need to register it in the testServiceProvider.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tools/Azure.Mcp.Tools.AppConfig/src/Commands/KeyValue/Lock/KeyValueLockSetCommand.cs | Inject IAppConfigService and stop resolving it from CommandContext during execution. |
| tools/Azure.Mcp.Tools.AppConfig/src/Commands/KeyValue/KeyValueSetCommand.cs | Inject IAppConfigService and use it directly in ExecuteAsync. |
| tools/Azure.Mcp.Tools.AppConfig/src/Commands/KeyValue/KeyValueGetCommand.cs | Inject IAppConfigService and stop calling context.GetService<IAppConfigService>(). |
| tools/Azure.Mcp.Tools.AppConfig/src/Commands/KeyValue/KeyValueDeleteCommand.cs | Inject IAppConfigService and use it directly in ExecuteAsync. |
| tools/Azure.Mcp.Tools.AppConfig/src/Commands/Account/AccountListCommand.cs | Inject IAppConfigService and use it directly in ExecuteAsync. |
| tools/Azure.Mcp.Tools.AppConfig/tests/Azure.Mcp.Tools.AppConfig.UnitTests/KeyValue/Lock/KeyValueLockSetCommandTests.cs | Update test to pass IAppConfigService into command constructor; no longer register it in DI. |
| tools/Azure.Mcp.Tools.AppConfig/tests/Azure.Mcp.Tools.AppConfig.UnitTests/KeyValue/KeyValueSetCommandTests.cs | Same as above for KeyValueSetCommand. |
| tools/Azure.Mcp.Tools.AppConfig/tests/Azure.Mcp.Tools.AppConfig.UnitTests/KeyValue/KeyValueGetCommandTests.cs | Same as above for KeyValueGetCommand. |
| tools/Azure.Mcp.Tools.AppConfig/tests/Azure.Mcp.Tools.AppConfig.UnitTests/KeyValue/KeyValueDeleteCommandTests.cs | Same as above for KeyValueDeleteCommand. |
| tools/Azure.Mcp.Tools.AppConfig/tests/Azure.Mcp.Tools.AppConfig.UnitTests/Account/AccountListCommandTests.cs | Same as above for AccountListCommand. |
alzimmermsft
approved these changes
Feb 26, 2026
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.
What does this PR do?
Step towards improving testability by reducing the usage of CommandContext.ServiceProvider. Making dependencies explicit.
GitHub issue number?
#158
Pre-merge Checklist
servers/Azure.Mcp.Server/CHANGELOG.mdand/orservers/Fabric.Mcp.Server/CHANGELOG.mdfor product changes (features, bug fixes, UI/UX, updated dependencies)servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationeng/scripts/Process-PackageReadMe.ps1. See Package README/servers/Azure.Mcp.Server/docs/azmcp-commands.mdand/or/docs/fabric-commands.md.\eng\scripts\Update-AzCommandsMetadata.ps1to update tool metadata in azmcp-commands.md (required for CI)ToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.json/servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline