Skip to content

DI Refactor: Azure.Mcp.Tools.AppService#1900

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-appservice-dependency-injection
Draft

DI Refactor: Azure.Mcp.Tools.AppService#1900
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-appservice-dependency-injection

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

Refactors Azure.Mcp.Tools.AppService commands to use constructor dependency injection instead of resolving IAppServiceService via context.GetService<T>() in ExecuteAsync. Part of #158.

Commands updated

  • WebappGetCommand
  • DatabaseAddCommand
  • AppSettingsGetCommand
  • AppSettingsUpdateCommand

Pattern applied

Before:

public sealed class WebappGetCommand(ILogger<WebappGetCommand> logger) : BaseAppServiceCommand<BaseAppServiceOptions>()
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var appServiceService = context.GetService<IAppServiceService>();
        var webapps = await appServiceService.GetWebAppsAsync(...);
    }
}

After:

public sealed class WebappGetCommand(ILogger<WebappGetCommand> logger, IAppServiceService appServiceService) : BaseAppServiceCommand<BaseAppServiceOptions>()
{
    private readonly IAppServiceService _appServiceService = appServiceService;

    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var webapps = await _appServiceService.GetWebAppsAsync(...);
    }
}

Tests updated

All unit tests updated to pass IAppServiceService directly to the command constructor, removing the ServiceCollection-based service provider setup previously used to satisfy context.GetService<T>().

Additional changes

  • Added AppServiceSetup to CommandFactoryHelpers.cs in the core unit tests so the factory correctly wires up AppService commands in integration-style tests.
  • Added a changelog entry documenting the testability improvement.
Original prompt

This section details on the original issue you should resolve

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

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

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.

…ice commands

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor Azure.Mcp.Tools.AppService for dependency injection DI Refactor: Azure.Mcp.Tools.AppService Mar 2, 2026
@@ -11,10 +11,11 @@

Copy link
Member

Choose a reason for hiding this comment

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

@copilot Perform Step 4 and Step 5 from the refactor plan.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in c6b9e13. Added AppServiceSetup to both arrays in CommandFactoryHelpers.cs (Step 4) and created a changelog entry at servers/Azure.Mcp.Server/changelog-entries/1772482309825.yaml (Step 5).

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: Untriaged

Development

Successfully merging this pull request may close these issues.

DI Refactor: Azure.Mcp.Tools.AppService

2 participants