Skip to content

DI Refactor: Azure.Mcp.Tools.Pricing#2080

Open
Copilot wants to merge 3 commits intomainfrom
copilot/mcp-158-refactor-azure-mcp-tools-pricing
Open

DI Refactor: Azure.Mcp.Tools.Pricing#2080
Copilot wants to merge 3 commits intomainfrom
copilot/mcp-158-refactor-azure-mcp-tools-pricing

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

  • Understand current code: PricingGetCommand resolves IPricingService via context.GetService<T>() in ExecuteAsync
  • Add IPricingService constructor parameter to PricingGetCommand and store as private field
  • Replace context.GetService<IPricingService>() with the injected _pricingService field
  • Update tests to pass _pricingService to the PricingGetCommand constructor
  • Build and run tests to verify changes (15/15 tests pass)
  • Merged latest main — no conflicts, build succeeds, all 15 tests still pass

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

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

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.

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Copilot AI changed the title [WIP] [microsoft/mcp#158] Refactor Azure.Mcp.Tools.Pricing for DI DI Refactor: Azure.Mcp.Tools.Pricing Mar 17, 2026
Copilot AI requested a review from conniey March 17, 2026 10:20
@joshfree joshfree added the Do Not Merge Do Not Merge / WIP PRs label Mar 17, 2026
@conniey
Copy link
Copy Markdown
Member

conniey commented Apr 15, 2026

@copilot pull latest changes, resolve merge conflicts, and check if this builds still

…tor-azure-mcp-tools-pricing

Co-authored-by: conniey <10136526+conniey@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 15, 2026

@copilot pull latest changes, resolve merge conflicts, and check if this builds still

Done — merged latest main (commit 1c720d0), no conflicts. Build succeeds and all 15 unit tests pass.

@conniey conniey marked this pull request as ready for review April 16, 2026 21:23
@conniey conniey requested review from a team and anannya03 as code owners April 16, 2026 21:23
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 Pricing tool command to use constructor-based dependency injection for IPricingService instead of resolving it from CommandContext at execution time, improving testability and aligning with DI patterns used across the toolset.

Changes:

  • Inject IPricingService into PricingGetCommand via constructor and use the injected field in ExecuteAsync.
  • Update unit tests to construct PricingGetCommand with the mocked IPricingService.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tools/Azure.Mcp.Tools.Pricing/src/Commands/PricingGetCommand.cs Switches from context.GetService<IPricingService>() to constructor-injected _pricingService.
tools/Azure.Mcp.Tools.Pricing/tests/Azure.Mcp.Tools.Pricing.UnitTests/PricingGetCommandTests.cs Updates command construction to pass _pricingService into the new constructor.

Comment thread tools/Azure.Mcp.Tools.Pricing/src/Commands/PricingGetCommand.cs
Copy link
Copy Markdown
Contributor

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Convention-aligned mechanical DI refactor. Matches the pattern from the reference PR (#1815, AppConfig) and every sibling DI refactor merged since: ManagedLustre (#2063), Marketplace (#2064), Kusto (#2061), KeyVault (#2060), LoadTesting (#2062), FoundryExtensions (#1990), Grafana (#1992), AppService (#1900), FunctionApp (#1991), Extension (#1988), Compute (#1914), AzureMigrate (#1909), AzureIsv (#1902), Authorization (#1901). Field naming (_pricingService), primary-constructor shape, and the 1:1 test rewiring all line up.

On the null-guard suggestion from the earlier review: the established Azure.Mcp.Tools command convention is plain assignment without ?? throw new ArgumentNullException. A grep across tools/Azure.Mcp.Tools.*/src/Commands/**/*Command.cs shows 0 of 54 DI-injected service fields use the guard pattern. The 19 files that do use it are all in Fabric.Mcp.Tools.OneLake, a separate toolset with its own conventions. Following the majority pattern here is correct.

No new findings. The failing build checks are the repo-wide NU1903 transitive vulnerability on System.Security.Cryptography.Xml 10.0.0 and reproduce on main, so they aren't caused by this PR.

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.Pricing

6 participants