Skip to content

DI Refactor: Azure.Mcp.Tools.Monitor#2081

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/microsoft-mcp-158-di-refactor-monitor
Draft

DI Refactor: Azure.Mcp.Tools.Monitor#2081
Copilot wants to merge 2 commits intomainfrom
copilot/microsoft-mcp-158-di-refactor-monitor

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

Removes context.GetService<T>() usage from all Monitor command ExecuteAsync implementations, replacing with constructor-injected dependencies to improve testability and make dependencies explicit.

Commands refactored

  • ActivityLogListCommand, ResourceLogQueryCommand, WorkspaceLogQueryCommand, TableListCommand, TableTypeListCommand, WorkspaceListCommand — now inject IMonitorService
  • MetricsDefinitionsCommand, MetricsQueryCommand — now inject IMonitorMetricsService
  • WebTestsCreateOrUpdateCommand, WebTestsGetCommand — now inject IMonitorWebTestService
  • EntityGetHealthCommand — now injects IMonitorHealthModelService

Before / After

// Before
public sealed class WorkspaceListCommand(ILogger<WorkspaceListCommand> logger) : ...
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var monitorService = context.GetService<IMonitorService>(); // resolved at call time
        ...
    }
}

// After
public sealed class WorkspaceListCommand(ILogger<WorkspaceListCommand> logger, IMonitorService monitorService) : ...
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var workspaces = await monitorService.ListWorkspaces(...); // injected at construction
        ...
    }
}

Tests

Unit test constructors updated to pass mocked services directly to commands instead of registering them in a ServiceCollection. Removed unused McpServer field/import from EntityGetHealthCommandTests.

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.Monitor</issue_title>
<issue_description>## Summary

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

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.

…ia constructor

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

3 participants