Skip to content

AppConfig: Remove usage of ServiceProvider in ExecuteAsync.#1815

Open
conniey wants to merge 3 commits intomicrosoft:mainfrom
conniey:conniey/service-provider-app-config
Open

AppConfig: Remove usage of ServiceProvider in ExecuteAsync.#1815
conniey wants to merge 3 commits intomicrosoft:mainfrom
conniey:conniey/service-provider-app-config

Conversation

@conniey
Copy link
Member

@conniey conniey commented Feb 26, 2026

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

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Updated servers/Azure.Mcp.Server/CHANGELOG.md and/or servers/Fabric.Mcp.Server/CHANGELOG.md for product changes (features, bug fixes, UI/UX, updated dependencies)
  • For MCP tool changes:
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes using script at eng/scripts/Process-PackageReadMe.ps1. See Package README
    • Updated command list in /servers/Azure.Mcp.Server/docs/azmcp-commands.md and/or /docs/fabric-commands.md
    • Run .\eng\scripts\Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated test prompts in /servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

@conniey conniey requested a review from a team as a code owner February 26, 2026 09:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IAppConfigService via primary constructors and use the injected instance in ExecuteAsync.
  • Updated AppConfig unit tests to construct commands with the injected IAppConfigService substitute and removed the need to register it in the test ServiceProvider.

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.

@github-project-automation github-project-automation bot moved this from Untriaged to In Progress in Azure MCP Server Feb 26, 2026
@conniey conniey enabled auto-merge (squash) February 27, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants