Skip to content

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

Open
Copilot wants to merge 2 commits intomainfrom
copilot/mcp-158-refactor-keyvault
Open

DI Refactor: Azure.Mcp.Tools.KeyVault#2060
Copilot wants to merge 2 commits intomainfrom
copilot/mcp-158-refactor-keyvault

Conversation

Copy link
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

DI Refactor: Azure.Mcp.Tools.KeyVault

2 participants