Skip to content

Make it easier to get endpoints within WithUrls callback #8640

@afscrome

Description

@afscrome

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

In the WithUrls callback, you probably want access to endpoints on the resource, however ctx.Resource is typed as IResource not IResourceWithEndpoints so you've got to go through a bit of casting, or go through `TryGetEndpoints' a bit awkward to get

.WithUrls(ctx =>
{
   var endpoint = ((IResourceWithEndpoints)ctx.Resource).GetEndpoint("http");
   //or
   if(ctx.Resource.TryGetEndpoints(out var endpoints))
   {
      var endpoint2 = endpoints.Single(x => x.Name == "http");
   }

   ctx.Urls.Add(new ResourceUrlAnnotation {
      Url = $"{endpoint.Url}/swagger",
      DisplayText = "swagger",
      Endpoint = endpoint
   });
})

Describe the solution you'd like

It would be nice if there was an easier way to get an endpoint in this callback, perhaps

.WithUrls(ctx =>
{
   var endpoint = ctx.GetEndpoint("http");
   // ...
})

Additional context

cc @DamianEdwards

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions