Skip to content

Using 9.2's WithUrl for the first time #8587

@afscrome

Description

@afscrome

Just tried out the new WithUrls option added in 9.2. Use case is I want to add a swagger url to my resource. We currently have a custom resource command to do this, but with the WithCommand we used being deprecated, seemed like moving to a native url was the best option.

First attempt was to try something like:

      var endpoint = builder.Resource.GetEndpoint(endpointName);
      builder.WithUrl($"{endpoint}/swagger", "swagger");

But this doesn't compile as the url has to be a string.

I found WithUrlForEndpoint which sort of works for what I want, however it replaces over the existing url, whereas I wanted the swagger link to be an additional link

      builder.WithUrlForEndpoint(endpointName, x =>
      {
         x.Url += "/swagger";
         x.DisplayText = "Swagger UI";
      });

There is WithUrls which creates an additional url, but now it has some strange UX whereby the Swagger url shows as soon as aspire starts up, but the http://loclhoast:1234 doesn't show up until the resource has finished waiting and actually starts

      builder.WithUrls(ctx => ctx.Urls.Add(new ResourceUrlAnnotation
         {
            Url = $"{endpoint.Url}/swagger",
            DisplayText = "Swagger UI",
         }));
  1. Should there be an overload of WithUrl() that allows url to be a ReferenceExpression?
  2. Is there a way to delay showing the url until the resource is actually started? (and should this be the default behavior)

Metadata

Metadata

Assignees

Labels

area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions