Skip to content

DI Refactor: Azure.Mcp.Tools.KeyVault#2060

Merged
alzimmermsft merged 2 commits intomainfrom
copilot/mcp-158-refactor-keyvault
Mar 17, 2026
Merged

DI Refactor: Azure.Mcp.Tools.KeyVault#2060
alzimmermsft merged 2 commits intomainfrom
copilot/mcp-158-refactor-keyvault

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 16, 2026

Refactors Azure.Mcp.Tools.KeyVault commands to receive IKeyVaultService via constructor injection rather than resolving it from context.GetService<T>() inside ExecuteAsync. Part of the broader DI refactor tracked in #158.

Commands updated

  • KeyGetCommand, KeyCreateCommand
  • SecretGetCommand, SecretCreateCommand
  • CertificateGetCommand, CertificateCreateCommand, CertificateImportCommand
  • AdminSettingsGetCommand

Pattern applied

Before:

public sealed class KeyGetCommand(ILogger<KeyGetCommand> logger) : SubscriptionCommand<KeyGetOptions>
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var keyVaultService = context.GetService<IKeyVaultService>();
        // ...
    }
}

After:

public sealed class KeyGetCommand(ILogger<KeyGetCommand> logger, IKeyVaultService keyVaultService) : SubscriptionCommand<KeyGetOptions>
{
    private readonly IKeyVaultService _keyVaultService = keyVaultService;

    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        // uses _keyVaultService directly
    }
}

Tests

Unit test constructors updated to pass the IKeyVaultService substitute directly to the command, removing the need to register it in a ServiceCollection.

Original prompt

This section details on the original issue you should resolve

<issue_title>DI Refactor: Azure.Mcp.Tools.KeyVault</issue_title>
<issue_description>## Summary

Refactor Azure.Mcp.Tools.KeyVault to use constructor dependency injection instead of resolving services via context.GetService<T>() in ExecuteAsync.

This is a sub-issue of #158.

Instructions

Follow the algorithm described in tools/di-refactor-plan.md with {ToolArea} = KeyVault.

An example PR is: #1815
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…commands

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Copilot AI changed the title [WIP] [mcp-158] Refactor Azure.Mcp.Tools.KeyVault for dependency injection DI Refactor: Azure.Mcp.Tools.KeyVault Mar 16, 2026
Copilot AI requested a review from conniey March 16, 2026 18:05
@conniey conniey marked this pull request as ready for review March 17, 2026 10:10
@conniey conniey requested review from a team, JonathanCrd and vcolin7 as code owners March 17, 2026 10:10
@conniey conniey requested review from alzimmermsft, Copilot, g2vinay, msalaman, saikoumudi and weshaggard and removed request for Copilot March 17, 2026 10:10
@github-project-automation github-project-automation bot moved this from Untriaged to In Progress in Azure MCP Server Mar 17, 2026
@alzimmermsft alzimmermsft merged commit 8076681 into main Mar 17, 2026
25 checks passed
@alzimmermsft alzimmermsft deleted the copilot/mcp-158-refactor-keyvault branch March 17, 2026 13:35
@github-project-automation github-project-automation bot moved this from In Progress to Done in Azure MCP Server Mar 17, 2026
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Apr 20, 2026
* Initial plan

* DI Refactor: inject IKeyVaultService via constructor in all KeyVault commands

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

DI Refactor: Azure.Mcp.Tools.KeyVault

3 participants