Skip to content

Conversation

DamianEdwards
Copy link
Member

@DamianEdwards DamianEdwards commented Apr 7, 2025

Description

Addresses feedback received about using WithUrls():

  • URL callbacks are now run later, during the BeforeResourceStarted event processing
  • Multiple URLs associated with the same endpoint are now properly supported and will be displayed on the dashboard
  • URLs that are not associated with an endpoint now aren't active until the resource enters the "Running" state
  • Added new overloads of WithUrl that accept ReferenceExpression and interpolated string
  • Tweaked doc comments to make it clearer when URLs are added vs. updated
  • Added new tests

Fixes #8587

Checklist

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

@github-actions github-actions bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Apr 7, 2025
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.

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

Comments suppressed due to low confidence (2)

tests/Aspire.Hosting.Tests/WithUrlsTests.cs:47

  • [nitpick] The test method name 'WithUrlsCallsCallbackAfterBeforeResourceStartedEvent' is ambiguous due to the repeated 'AfterBefore' phrasing. Consider renaming it to 'WithUrlsCallsCallbackAfterResourceStartedEvent' for clarity.
public async Task WithUrlsCallsCallbackAfterBeforeResourceStartedEvent()

src/Aspire.Hosting/Dcp/ResourceSnapshotBuilder.cs:213

  • The use of the null-forgiving operator on 'endpointUrl.Endpoint' assumes this property is never null. Consider adding a null-check or ensuring via code invariants that 'endpointUrl.Endpoint' is always set to avoid potential runtime exceptions.
urls.Add(new(Name: endpointUrl.Endpoint!.EndpointName, Url: endpointUrl.Url, IsInternal: false) { IsInactive = isInactive, DisplayProperties = new(endpointUrl.DisplayText ?? "", endpointUrl.DisplayOrder ?? 0) });

@DamianEdwards
Copy link
Member Author

/backport to release/9.2

Copy link
Contributor

github-actions bot commented Apr 7, 2025

Started backporting to release/9.2: https://github.com/dotnet/aspire/actions/runs/14321482119

}

private async Task OnResourceStarting(OnResourceStartingContext context)
{
// Call the callbacks to configure resource URLs
await ProcessUrls(context.Resource, context.CancellationToken).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

What happens if this fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question given it's user code. This didn't change in this PR of course, but there's no error handling here right now. I see that the environment callback stuff doesn't handle errors in its callbacks either though.

Copy link
Member

Choose a reason for hiding this comment

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

So same experience, failed to start

@DamianEdwards DamianEdwards requested a review from davidfowl April 8, 2025 00:45
@DamianEdwards DamianEdwards merged commit f315166 into main Apr 8, 2025
174 checks passed
@DamianEdwards DamianEdwards deleted the damianedwards/WithUrlsUpdates branch April 8, 2025 01:07
@github-actions github-actions bot locked and limited conversation to collaborators May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using 9.2's WithUrl for the first time
2 participants