Skip to content

DI Refactor: Azure.Mcp.Tools.Policy#2078

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

DI Refactor: Azure.Mcp.Tools.Policy#2078
Copilot wants to merge 2 commits intomainfrom
copilot/mcp-158-di-refactor-azure-mcp-tools-policy

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

Part of the broader DI refactor (#158) — removes context.GetService<IPolicyService>() from ExecuteAsync in favor of constructor injection.

Changes

  • PolicyAssignmentListCommand: Added IPolicyService as a constructor parameter; replaced runtime service resolution with the injected field.
  • PolicyAssignmentListCommandTests: Pass mock service directly to constructor; removed ServiceCollection registration of the mock.

Before:

public sealed class PolicyAssignmentListCommand(ILogger<PolicyAssignmentListCommand> logger)
    : SubscriptionCommand<PolicyAssignmentListOptions>
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var policyService = context.GetService<IPolicyService>();
        var assignments = await policyService.ListPolicyAssignmentsAsync(...);
    }
}

After:

public sealed class PolicyAssignmentListCommand(ILogger<PolicyAssignmentListCommand> logger, IPolicyService policyService)
    : SubscriptionCommand<PolicyAssignmentListOptions>
{
    private readonly IPolicyService _policyService = policyService;

    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var assignments = await _policyService.ListPolicyAssignmentsAsync(...);
    }
}
Original prompt

This section details on the original issue you should resolve

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

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

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.

…stCommand

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Copilot AI changed the title [WIP] [mcp-158] Refactor Azure.Mcp.Tools.Policy for dependency injection DI Refactor: Azure.Mcp.Tools.Policy Mar 17, 2026
Copilot AI requested a review from conniey March 17, 2026 10:18
@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.Policy

3 participants