Skip to content

DI Refactor: Azure.Mcp.Tools.Marketplace#2064

Merged
alzimmermsft merged 2 commits intomainfrom
copilot/microsoft-mcp-158-di-refactor-azure-mcp-tools-mark
Mar 17, 2026
Merged

DI Refactor: Azure.Mcp.Tools.Marketplace#2064
alzimmermsft merged 2 commits intomainfrom
copilot/microsoft-mcp-158-di-refactor-azure-mcp-tools-mark

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 16, 2026

Part of the broader DI refactor (#158): ProductGetCommand and ProductListCommand were resolving IMarketplaceService lazily via context.GetService<T>() inside ExecuteAsync instead of using constructor injection.

Changes

  • ProductGetCommand / ProductListCommand: Added IMarketplaceService as a constructor parameter; removed runtime context.GetService<IMarketplaceService>() calls.
// Before
public sealed class ProductGetCommand(ILogger<ProductGetCommand> logger) : SubscriptionCommand<ProductGetOptions>
{
    public override async Task<CommandResponse> ExecuteAsync(...)
    {
        var marketplaceService = context.GetService<IMarketplaceService>(); // ❌
        ...
    }
}

// After
public sealed class ProductGetCommand(ILogger<ProductGetCommand> logger, IMarketplaceService marketplaceService) : SubscriptionCommand<ProductGetOptions>
{
    private readonly IMarketplaceService _marketplaceService = marketplaceService; // ✅
    ...
}
  • Unit tests: Updated constructors to inject the mock service directly into the command rather than registering it in the service collection.
Original prompt

This section details on the original issue you should resolve

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

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

An example PR is: #1815
</issue_description>

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


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…Command and ProductListCommand

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

Refactors the Marketplace tool commands to use constructor dependency injection for IMarketplaceService rather than resolving it from CommandContext during execution, improving explicitness and testability as part of the broader DI refactor effort.

Changes:

  • Inject IMarketplaceService into ProductGetCommand and ProductListCommand via primary constructors.
  • Remove context.GetService<IMarketplaceService>() usage from ExecuteAsync.
  • Update unit tests to pass the mocked IMarketplaceService directly into command constructors.

Reviewed changes

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

File Description
tools/Azure.Mcp.Tools.Marketplace/src/Commands/Product/ProductGetCommand.cs Switches product “get” command to constructor-injected IMarketplaceService and uses it in ExecuteAsync.
tools/Azure.Mcp.Tools.Marketplace/src/Commands/Product/ProductListCommand.cs Switches product “list” command to constructor-injected IMarketplaceService and uses it in ExecuteAsync.
tools/Azure.Mcp.Tools.Marketplace/tests/Azure.Mcp.Tools.Marketplace.UnitTests/Product/ProductGetCommandTests.cs Updates tests to construct the command with a mocked IMarketplaceService instead of registering it in the service collection.
tools/Azure.Mcp.Tools.Marketplace/tests/Azure.Mcp.Tools.Marketplace.UnitTests/Product/ProductListCommandTests.cs Updates tests to construct the command with a mocked IMarketplaceService instead of registering it in the service collection.

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 940a314 into main Mar 17, 2026
30 checks passed
@alzimmermsft alzimmermsft deleted the copilot/microsoft-mcp-158-di-refactor-azure-mcp-tools-mark branch March 17, 2026 13:35
@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

* DI refactor: inject IMarketplaceService via constructor in ProductGetCommand and ProductListCommand

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

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
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: Done

Development

Successfully merging this pull request may close these issues.

DI Refactor: Azure.Mcp.Tools.Marketplace

4 participants