Skip to content

DI Refactor: Azure.Mcp.Tools.AzureMigrate#1909

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-azuremigrate-dependency-injection
Draft

DI Refactor: Azure.Mcp.Tools.AzureMigrate#1909
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-azuremigrate-dependency-injection

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

Replaces context.GetService<T>() calls inside ExecuteAsync with constructor-injected dependencies in the AzureMigrate commands, consistent with the broader DI refactor tracked in #158.

Changes

  • GetGuidanceCommand: inject IPlatformLandingZoneGuidanceService via constructor; use _guidanceService field directly in ExecuteAsync
  • RequestCommand: inject IPlatformLandingZoneService and AzureMigrateProjectHelper via constructor; remove both context.GetService<>() calls; update HandleCreateMigrateProjectActionAsync to accept AzureMigrateProjectHelper as a parameter instead of CommandContext
  • Tests: pass services directly to command constructors instead of relying on the service provider in CommandContext

Before:

public sealed class RequestCommand(ILogger<RequestCommand> logger) : SubscriptionCommand<RequestOptions>()
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var platformLandingZoneService = context.GetService<IPlatformLandingZoneService>();
        var deploymentHelper = context.GetService<AzureMigrateProjectHelper>();
        ...
    }
}

After:

public sealed class RequestCommand(
    ILogger<RequestCommand> logger,
    IPlatformLandingZoneService platformLandingZoneService,
    AzureMigrateProjectHelper azureMigrateProjectHelper) : SubscriptionCommand<RequestOptions>()
{
    private readonly IPlatformLandingZoneService _platformLandingZoneService = platformLandingZoneService;
    private readonly AzureMigrateProjectHelper _azureMigrateProjectHelper = azureMigrateProjectHelper;

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

Invoking Livetests

Copilot submitted PRs are not trustworthy by default. Users with write access to the repo need to validate the contents of this PR before leaving a comment with the text /azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.

Original prompt

This section details on the original issue you should resolve

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

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

An example PR is: #1815
</issue_description>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor Azure.Mcp.Tools.AzureMigrate to use constructor DI DI Refactor: Azure.Mcp.Tools.AzureMigrate Mar 3, 2026
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.AzureMigrate

2 participants