Partilhar via


ResourceBuilderExtensions.WithReference Method

Definition

Overloads

WithReference<TDestination>(IResourceBuilder<TDestination>, String, Uri)

Injects service discovery 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 "services__{name}__default__0={uri}."

WithReference<TDestination>(IResourceBuilder<TDestination>, EndpointReference)

Injects service discovery information from the specified endpoint into the project resource using the source resource's name as the service name. Each endpoint will be injected using the format "services__{sourceResourceName}{endpointName}{endpointIndex}={uriString}."

WithReference<TDestination>(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>)

Injects service discovery 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 "services__{sourceResourceName}{endpointName}{endpointIndex}={uriString}."

WithReference<TDestination>(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, String, Boolean)

Injects a connection string as an environment variable from the source resource into the destination resource, using the source resource's name as the connection string name (if not overridden). The format of the environment variable will be "ConnectionStrings__{sourceResourceName}={connectionString}."

Each resource defines the format of the connection string value. The underlying connection string value can be retrieved using GetConnectionStringAsync(CancellationToken).

Connection strings are also resolved by the configuration system (appSettings.json in the AppHost project, or environment variables). If a connection string is not found on the resource, the configuration system will be queried for a connection string using the resource's name.

WithReference<TDestination>(IResourceBuilder<TDestination>, String, Uri)

Source:
ResourceBuilderExtensions.cs
Source:
ResourceBuilderExtensions.cs

Injects service discovery 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 "services__{name}__default__0={uri}."

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> WithReference<TDestination> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> builder, string name, Uri uri) where TDestination : Aspire.Hosting.ApplicationModel.IResourceWithEnvironment;
static member WithReference : Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> * string * Uri -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)
<Extension()>
Public Function WithReference(Of TDestination As IResourceWithEnvironment) (builder As IResourceBuilder(Of TDestination), name As String, uri As Uri) As IResourceBuilder(Of TDestination)

Type Parameters

TDestination

Parameters

builder
IResourceBuilder<TDestination>

The resource where the service discovery information will be injected.

name
String

The name of the service.

uri
Uri

The uri of the service.

Returns

IResourceBuilder<TDestination>

A reference to the IResourceBuilder<T>.

Applies to

WithReference<TDestination>(IResourceBuilder<TDestination>, EndpointReference)

Source:
ResourceBuilderExtensions.cs
Source:
ResourceBuilderExtensions.cs

Injects service discovery information from the specified endpoint into the project resource using the source resource's name as the service name. Each endpoint will be injected using the format "services__{sourceResourceName}{endpointName}{endpointIndex}={uriString}."

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> WithReference<TDestination> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> builder, Aspire.Hosting.ApplicationModel.EndpointReference endpointReference) where TDestination : Aspire.Hosting.ApplicationModel.IResourceWithEnvironment;
static member WithReference : Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> * Aspire.Hosting.ApplicationModel.EndpointReference -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)
<Extension()>
Public Function WithReference(Of TDestination As IResourceWithEnvironment) (builder As IResourceBuilder(Of TDestination), endpointReference As EndpointReference) As IResourceBuilder(Of TDestination)

Type Parameters

TDestination

The destination resource.

Parameters

builder
IResourceBuilder<TDestination>

The resource where the service discovery information will be injected.

endpointReference
EndpointReference

The endpoint from which to extract the url.

Returns

IResourceBuilder<TDestination>

A reference to the IResourceBuilder<T>.

Applies to

WithReference<TDestination>(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>)

Source:
ResourceBuilderExtensions.cs
Source:
ResourceBuilderExtensions.cs

Injects service discovery 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 "services__{sourceResourceName}{endpointName}{endpointIndex}={uriString}."

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> WithReference<TDestination> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> builder, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.IResourceWithServiceDiscovery> source) where TDestination : Aspire.Hosting.ApplicationModel.IResourceWithEnvironment;
static member WithReference : Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> * Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.IResourceWithServiceDiscovery> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)
<Extension()>
Public Function WithReference(Of TDestination As IResourceWithEnvironment) (builder As IResourceBuilder(Of TDestination), source As IResourceBuilder(Of IResourceWithServiceDiscovery)) As IResourceBuilder(Of TDestination)

Type Parameters

TDestination

The destination resource.

Parameters

builder
IResourceBuilder<TDestination>

The resource where the service discovery information will be injected.

source
IResourceBuilder<IResourceWithServiceDiscovery>

The resource from which to extract service discovery information.

Returns

IResourceBuilder<TDestination>

A reference to the IResourceBuilder<T>.

Applies to

WithReference<TDestination>(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, String, Boolean)

Source:
ResourceBuilderExtensions.cs
Source:
ResourceBuilderExtensions.cs

Injects a connection string as an environment variable from the source resource into the destination resource, using the source resource's name as the connection string name (if not overridden). The format of the environment variable will be "ConnectionStrings__{sourceResourceName}={connectionString}."

Each resource defines the format of the connection string value. The underlying connection string value can be retrieved using GetConnectionStringAsync(CancellationToken).

Connection strings are also resolved by the configuration system (appSettings.json in the AppHost project, or environment variables). If a connection string is not found on the resource, the configuration system will be queried for a connection string using the resource's name.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> WithReference<TDestination> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<TDestination> builder, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.IResourceWithConnectionString> source, string? connectionName = default, bool optional = false) where TDestination : Aspire.Hosting.ApplicationModel.IResourceWithEnvironment;
static member WithReference : Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> * Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.IResourceWithConnectionString> * string * bool -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'Destination (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)> (requires 'Destination :> Aspire.Hosting.ApplicationModel.IResourceWithEnvironment)
<Extension()>
Public Function WithReference(Of TDestination As IResourceWithEnvironment) (builder As IResourceBuilder(Of TDestination), source As IResourceBuilder(Of IResourceWithConnectionString), Optional connectionName As String = Nothing, Optional optional As Boolean = false) As IResourceBuilder(Of TDestination)

Type Parameters

TDestination

The destination resource.

Parameters

builder
IResourceBuilder<TDestination>

The resource where connection string will be injected.

source
IResourceBuilder<IResourceWithConnectionString>

The resource from which to extract the connection string.

connectionName
String

An override of the source resource's name for the connection string. The resulting connection string will be "ConnectionStrings__connectionName" if this is not null.

optional
Boolean

true to allow a missing connection string; false to throw an exception if the connection string is not found.

Returns

IResourceBuilder<TDestination>

A reference to the IResourceBuilder<T>.

Exceptions

Throws an exception if the connection string resolves to null. It can be null if the resource has no connection string, and if the configuration has no connection string for the source resource.

Applies to