Skip to content

DI Refactor: Azure.Mcp.Tools.MySql#2077

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/mcp-158-refactor-azure-mcp-tools-mysql
Draft

DI Refactor: Azure.Mcp.Tools.MySql#2077
Copilot wants to merge 2 commits intomainfrom
copilot/mcp-158-refactor-azure-mcp-tools-mysql

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

Refactors Azure.Mcp.Tools.MySql commands to use constructor dependency injection for IMySqlService instead of resolving it via context.GetService<T>() in ExecuteAsync. Sub-issue of #158.

Changes

Commands

All 6 command classes now accept IMySqlService via constructor and store it as a private readonly field, eliminating runtime service resolution:

// Before
public sealed class DatabaseQueryCommand(ILogger<DatabaseQueryCommand> logger) : BaseDatabaseCommand<DatabaseQueryOptions>(logger)
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var mysqlService = context.GetService<IMySqlService>() ?? throw new InvalidOperationException("...");
        // ...
    }
}

// After
public sealed class DatabaseQueryCommand(ILogger<DatabaseQueryCommand> logger, IMySqlService mysqlService) : BaseDatabaseCommand<DatabaseQueryOptions>(logger)
{
    private readonly IMySqlService _mysqlService = mysqlService;

    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var result = await _mysqlService.ExecuteQueryAsync(...);
        // ...
    }
}

Affected commands: MySqlListCommand, DatabaseQueryCommand, ServerConfigGetCommand, ServerParamGetCommand, ServerParamSetCommand, TableSchemaGetCommand.

Tests

Removed IServiceProvider/ServiceCollection setup from all command test classes. Mock service is now passed directly to command constructors.

No setup changes needed

MySqlSetup.ConfigureServices already registers IMySqlService and all commands as singletons — the DI container resolves the new constructor dependency automatically.

Original prompt

This section details on the original issue you should resolve

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

Refactor Azure.Mcp.Tools.MySql 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} = MySql.

An example PR is: #1815
</issue_description>

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


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…ctor

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Copilot AI changed the title [WIP] [mcp-158] Refactor Azure.Mcp.Tools.MySql to use dependency injection DI Refactor: Azure.Mcp.Tools.MySql Mar 17, 2026
Copilot AI requested a review from conniey March 17, 2026 10:27
@joshfree joshfree added the Do Not Merge Do Not Merge / WIP PRs label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Do Not Merge Do Not Merge / WIP PRs

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

DI Refactor: Azure.Mcp.Tools.MySql

3 participants