Skip to content

DI Refactor: Azure.Mcp.Tools.LoadTesting#2062

Merged
alzimmermsft merged 3 commits intomainfrom
copilot/mcp-158-refactor-loadtesting
Mar 17, 2026
Merged

DI Refactor: Azure.Mcp.Tools.LoadTesting#2062
alzimmermsft merged 3 commits intomainfrom
copilot/mcp-158-refactor-loadtesting

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 16, 2026

Removes context.GetService<ILoadTestingService>() calls from ExecuteAsync across all LoadTesting commands, replacing them with constructor-injected dependencies per the pattern established in #158.

Commands updated

  • TestGetCommand
  • TestCreateCommand
  • TestResourceCreateCommand
  • TestResourceListCommand
  • TestRunCreateOrUpdateCommand
  • TestRunGetCommand

Pattern applied

// Before
public sealed class TestGetCommand(ILogger<TestGetCommand> logger) : BaseLoadTestingCommand<TestGetOptions>
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var service = context.GetService<ILoadTestingService>(); // resolved at call time
        var results = await service.GetTestAsync(...);
    }
}

// After
public sealed class TestGetCommand(ILogger<TestGetCommand> logger, ILoadTestingService loadTestingService) : BaseLoadTestingCommand<TestGetOptions>
{
    private readonly ILoadTestingService _loadTestingService = loadTestingService;

    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var results = await _loadTestingService.GetTestAsync(...);
    }
}

Tests updated

All unit tests now pass the mock ILoadTestingService directly to the command constructor instead of registering it in the ServiceCollection, removing the indirect DI container dependency from test setup.

Original prompt

This section details on the original issue you should resolve

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

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

An example PR is: #1815
</issue_description>

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


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Copilot AI changed the title [WIP] [mcp-158] Refactor Azure.Mcp.Tools.LoadTesting for dependency injection DI Refactor: Azure.Mcp.Tools.LoadTesting Mar 16, 2026
Copilot AI requested a review from conniey March 16, 2026 18:05
@conniey conniey marked this pull request as ready for review March 17, 2026 10:04
@conniey conniey requested a review from a team as a code owner March 17, 2026 10:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Azure.Mcp.Tools.LoadTesting command implementations to use constructor-injected ILoadTestingService rather than resolving it from CommandContext during ExecuteAsync, aligning LoadTesting with the DI pattern referenced in #158.

Changes:

  • Updated LoadTesting commands to accept ILoadTestingService via constructor injection and to call the injected instance inside ExecuteAsync.
  • Updated unit tests to construct commands with a mocked ILoadTestingService directly instead of registering it in a ServiceCollection.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/Azure.Mcp.Tools.LoadTesting/src/Commands/LoadTestRun/TestRunGetCommand.cs Switches from context.GetService<ILoadTestingService>() to constructor-injected service.
tools/Azure.Mcp.Tools.LoadTesting/src/Commands/LoadTestRun/TestRunCreateOrUpdateCommand.cs Same DI refactor for create/update test run flow.
tools/Azure.Mcp.Tools.LoadTesting/src/Commands/LoadTestResource/TestResourceListCommand.cs Same DI refactor for listing load test resources.
tools/Azure.Mcp.Tools.LoadTesting/src/Commands/LoadTestResource/TestResourceCreateCommand.cs Same DI refactor for creating load test resources.
tools/Azure.Mcp.Tools.LoadTesting/src/Commands/LoadTest/TestGetCommand.cs Same DI refactor for getting a test definition.
tools/Azure.Mcp.Tools.LoadTesting/src/Commands/LoadTest/TestCreateCommand.cs Same DI refactor for creating a test definition.
tools/Azure.Mcp.Tools.LoadTesting/tests/Azure.Mcp.Tools.LoadTesting.UnitTests/TestRunGetCommandTests.cs Updates tests to pass mocked service directly to command constructor.
tools/Azure.Mcp.Tools.LoadTesting/tests/Azure.Mcp.Tools.LoadTesting.UnitTests/TestRunCreateOrUpdateCommandTests.cs Updates tests to pass mocked service directly to command constructor.
tools/Azure.Mcp.Tools.LoadTesting/tests/Azure.Mcp.Tools.LoadTesting.UnitTests/TestResourcesListCommandTests.cs Updates tests to pass mocked service directly to command constructor.
tools/Azure.Mcp.Tools.LoadTesting/tests/Azure.Mcp.Tools.LoadTesting.UnitTests/TestResourceCreateTests.cs Updates tests to pass mocked service directly to command constructor.
tools/Azure.Mcp.Tools.LoadTesting/tests/Azure.Mcp.Tools.LoadTesting.UnitTests/TestGetCommandTests.cs Updates tests to pass mocked service directly to command constructor.
tools/Azure.Mcp.Tools.LoadTesting/tests/Azure.Mcp.Tools.LoadTesting.UnitTests/TestCreateCommandTests.cs Updates tests to pass mocked service directly to command constructor.

You can also share your feedback on Copilot code review. Take the survey.

@github-project-automation github-project-automation bot moved this from Untriaged to In Progress in Azure MCP Server Mar 17, 2026
@alzimmermsft alzimmermsft merged commit 431b6ca into main Mar 17, 2026
27 checks passed
@alzimmermsft alzimmermsft deleted the copilot/mcp-158-refactor-loadtesting branch March 17, 2026 13:37
@github-project-automation github-project-automation bot moved this from In Progress to Done in Azure MCP Server Mar 17, 2026
colbytimm pushed a commit to colbytimm/microsoft-mcp that referenced this pull request Apr 20, 2026
* Initial plan

* refactor: DI refactor for Azure.Mcp.Tools.LoadTesting commands

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>

* Delete servers/Azure.Mcp.Server/changelog-entries/1773500000000.yaml

Remove unnecessary changelog

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Co-authored-by: Connie Yau <conniey@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

DI Refactor: Azure.Mcp.Tools.LoadTesting

4 participants