Skip to content
40 changes: 40 additions & 0 deletions src/Aspire.Hosting/ResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,46 @@ public static IResourceBuilder<TDestination> WithReference<TDestination>(this IR
return builder;
}

/// <summary>
/// Injects endpoint information as environment variables from the project resource into the destination resource, using the source resource's name as the service name.
/// Each endpoint defined on the project resource will be injected using the format defined by the <see cref="ReferenceEnvironmentInjectionAnnotation"/> on the destination resource, i.e.
Comment thread
Falco20019 marked this conversation as resolved.
Outdated
/// either "services__{sourceResourceName}__{endpointName}__{endpointIndex}={uriString}" for .NET service discovery, or "{RESOURCE_ENDPOINT}={uri}" for endpoint injection.
/// </summary>
Comment thread
Falco20019 marked this conversation as resolved.
/// <typeparam name="TDestination">The destination resource.</typeparam>
/// <param name="builder">The resource where the endpoint information will be injected.</param>
/// <param name="source">The resource from which to extract endpoint information.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
[AspireExport("withEndpoints", Description = "Adds all endpoint references to another resource")]
public static IResourceBuilder<TDestination> WithReference<TDestination>(this IResourceBuilder<TDestination> builder, IResourceBuilder<IResourceWithEndpoints> source)
Comment thread
Falco20019 marked this conversation as resolved.
Outdated
where TDestination : IResourceWithEnvironment
Comment thread
Falco20019 marked this conversation as resolved.
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);

ApplyEndpoints(builder, source.Resource);
return builder;
}

/// <summary>
/// Injects endpoint information as environment variables from the project resource into the destination resource, using the source resource's name as the service name.
/// Each endpoint defined on the project resource will be injected using the format defined by the <see cref="ReferenceEnvironmentInjectionAnnotation"/> on the destination resource, i.e.
/// either "services__{name}__{endpointName}__{endpointIndex}={uriString}" for .NET service discovery, or "{name}_{ENDPOINT}={uri}" for endpoint injection.
/// </summary>
/// <typeparam name="TDestination">The destination resource.</typeparam>
/// <param name="builder">The resource where the endpoint information will be injected.</param>
/// <param name="source">The resource from which to extract endpoint information.</param>
/// <param name="name">The name of the resource for the environment variable.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
Comment thread
Falco20019 marked this conversation as resolved.
public static IResourceBuilder<TDestination> WithReference<TDestination>(this IResourceBuilder<TDestination> builder, IResourceBuilder<IResourceWithEndpoints> source, string name)
where TDestination : IResourceWithEnvironment
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);

ApplyEndpoints(builder, source.Resource, endpointName: null, name);
return builder;
}

/// <summary>
/// Injects service discovery and endpoint information as environment variables from the uri into the destination resource, using the name as the service name.
/// The uri will be injected using the format defined by the <see cref="ReferenceEnvironmentInjectionAnnotation"/> on the destination resource, i.e.
Expand Down
Loading