Поделиться через


ResourceBuilderExtensions.WithUrls Method

Definition

Overloads

WithUrls<T>(IResourceBuilder<T>, Action<ResourceUrlsCallbackContext>)

Registers a callback to customize the URLs displayed for the resource.

WithUrls<T>(IResourceBuilder<T>, Func<ResourceUrlsCallbackContext,Task>)

Registers an async callback to customize the URLs displayed for the resource.

WithUrls<T>(IResourceBuilder<T>, Action<ResourceUrlsCallbackContext>)

Source:
ResourceBuilderExtensions.cs

Registers a callback to customize the URLs displayed for the resource.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithUrls<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, Action<Aspire.Hosting.ApplicationModel.ResourceUrlsCallbackContext> callback) where T : Aspire.Hosting.ApplicationModel.IResource;
static member WithUrls : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> * Action<Aspire.Hosting.ApplicationModel.ResourceUrlsCallbackContext> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)
<Extension()>
Public Function WithUrls(Of T As IResource) (builder As IResourceBuilder(Of T), callback As Action(Of ResourceUrlsCallbackContext)) As IResourceBuilder(Of T)

Type Parameters

T

The resource type.

Parameters

builder
IResourceBuilder<T>

The builder for the resource.

callback
Action<ResourceUrlsCallbackContext>

The callback that will customize URLs for the resource.

Returns

The IResourceBuilder<T>.

Examples

Update all displayed URLs to have display text:

var frontend = builder.AddProject<Projects.Frontend>("frontend")
                      .WithUrls(c =>
                      {
                          foreach (var url in c.Urls)
                          {
                              if (string.IsNullOrEmpty(url.DisplayText))
                              {
                                  url.DisplayText = "frontend";
                              }
                          }
                      });

Update endpoint URLs to use a custom host name based on the resource name:

var frontend = builder.AddProject<Projects.Frontend>("frontend")
                      .WithUrls(c =>
                      {
                          foreach (var url in c.Urls)
                          {
                              if (url.Endpoint is not null)
                              {
                                  var uri = new UriBuilder(url.Url) { Host = $"{c.Resource.Name}.localhost" };
                                  url.Url = uri.ToString();
                              }
                          }
                      });

Remarks

The callback will be executed after endpoints have been allocated for this resource.
This allows you to modify any URLs for the resource, including adding, modifying, or even deletion.
Note that any endpoints on the resource will automatically get a corresponding URL added for them.

Applies to

WithUrls<T>(IResourceBuilder<T>, Func<ResourceUrlsCallbackContext,Task>)

Source:
ResourceBuilderExtensions.cs

Registers an async callback to customize the URLs displayed for the resource.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithUrls<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, Func<Aspire.Hosting.ApplicationModel.ResourceUrlsCallbackContext,System.Threading.Tasks.Task> callback) where T : Aspire.Hosting.ApplicationModel.IResource;
static member WithUrls : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> * Func<Aspire.Hosting.ApplicationModel.ResourceUrlsCallbackContext, System.Threading.Tasks.Task> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)
<Extension()>
Public Function WithUrls(Of T As IResource) (builder As IResourceBuilder(Of T), callback As Func(Of ResourceUrlsCallbackContext, Task)) As IResourceBuilder(Of T)

Type Parameters

T

The resource type.

Parameters

builder
IResourceBuilder<T>

The builder for the resource.

callback
Func<ResourceUrlsCallbackContext,Task>

The async callback that will customize URLs for the resource.

Returns

The IResourceBuilder<T>.

Remarks

The callback will be executed after endpoints have been allocated for this resource.
This allows you to modify any URLs for the resource, including adding, modifying, or even deletion.
Note that any endpoints on the resource will automatically get a corresponding URL added for them.

Applies to