Skip to content

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Jul 14, 2025

Description

ResourceCommandService.ExecuteCommandAsync(string, ...) takes a resourceId and matches to the resource with that resourceId. That includes the suffix for DCP resources, e.g. cache-sfsdfsdf. This could be confusing as people often only think about the resource name, e.g. cache.

PR improves XML docs for API. It also allows the method to match on resource name if there are no replicas.

Fixes #10224

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@JamesNK
Copy link
Member Author

JamesNK commented Jul 14, 2025

cc @afscrome

Copy link
Contributor

@Copilot 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

Implements fallback matching by resource name when no replicas exist and clarifies this behavior in XML documentation, plus adds corresponding unit tests.

  • Adds fallback logic in ResourceNotificationService to match resources by name if only one exists.
  • Updates XML docs in both ResourceNotificationService and ResourceCommandService to explain resource ID vs. name matching.
  • Introduces tests covering both failure and success scenarios for resource name matching in ResourceCommandService.

Reviewed Changes

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

File Description
tests/Aspire.Hosting.Tests/ResourceCommandServiceTests.cs Adds tests for resource name matching (failure and success)
src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs Implements name-based fallback lookup and updates XML docs
src/Aspire.Hosting/ApplicationModel/ResourceCommandService.cs Updates XML docs to clarify resourceId vs. resourceName logic
Comments suppressed due to low confidence (2)

src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs:448

  • Fix the grammar and spelling in this XML comment: change "can be also be used" to "can also be used" and correct "specifing" to "specifying".
    /// </para>

src/Aspire.Hosting/ApplicationModel/ResourceCommandService.cs:37

  • Fix the grammar and spelling in this XML comment: change "can be also be used" to "can also be used" and correct "specifing" to "specifying".
    /// The resource name can be also be used to retrieve the resource state, but it must be unique. If there are multiple resources with the same name, then this method will not return a match.

JamesNK and others added 2 commits July 14, 2025 08:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@JamesNK JamesNK added this to the 9.4 milestone Jul 14, 2025
else
{
// Second match found, so we can't return a match based on the name.
nameMatch = null;
Copy link
Member

Choose a reason for hiding this comment

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

Replicas?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

@JamesNK JamesNK merged commit 69fb5a3 into main Jul 14, 2025
276 checks passed
@JamesNK JamesNK deleted the jamesnk/resourceexecuteservice-matchname branch July 14, 2025 04:53
@JamesNK
Copy link
Member Author

JamesNK commented Jul 14, 2025

/backport to release/9.4

Copy link
Contributor

Started backporting to release/9.4: https://github.com/dotnet/aspire/actions/runs/16258280487

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pit of failure with ResourceCommandService.ExecuteCommandAsync(string resourceId, ...)
2 participants