ResourceBuilderExtensions
Class static net8.0
Provides extension methods for configuring resources with environment variables.
namespace Aspire.Hosting;
public static class ResourceBuilderExtensions{ // ...} 89 members
Methods89
Section titled MethodsAsHttp2Service(IResourceBuilder<T>)extensionats export Configures a resource to mark all endpoints' transport as HTTP/2. This is useful for HTTP/2 services that need prior knowledge.
ClearContainerFilesSources(IResourceBuilder<T>)extensionats export Removes any container files source annotation from the resource being built.
ExcludeFromManifest(IResourceBuilder<T>)extensionats export Excludes a resource from being published to the manifest.
ExcludeFromMcp(IResourceBuilder<T>)extensionats export Exclude the resource from MCP operations using the Aspire MCP server. The resource is excluded from results that return resources, console logs and telemetry.
GetConnectionProperty(IResourceWithConnectionString, string)extensionats export Retrieves the value of a specified connection property from the resource's connection properties.
GetEndpoint(IResourceBuilder<T>, string, NetworkIdentifier)extensionats ignored Gets an
EndpointReference by name from the resource. These endpoints are declared either using ResourceBuilderExtensions.WithEndpoint or by launch settings (for project resources). The EndpointReference can be used to resolve the address of the endpoint in ResourceBuilderExtensions.WithEnvironment. GetEndpoint(IResourceBuilder<T>, string)extensionats export Gets an
EndpointReference by name from the resource. These endpoints are declared either using ResourceBuilderExtensions.WithEndpoint or by launch settings (for project resources). The EndpointReference can be used to resolve the address of the endpoint in ResourceBuilderExtensions.WithEnvironment. PublishWithContainerFiles(IResourceBuilder<T>, IResourceBuilder<IResourceWithContainerFiles>, string)extensionats export Configures the resource to copy container files from the specified source resource during publishing.
SubscribeHttpsEndpointsUpdate(IResourceBuilder<TResource>, Action<HttpsEndpointUpdateCallbackContext>)extensionexperimentalats ignoredIResourceBuilder<TResource> Subscribes to the
BeforeStartEvent and invokes the specified callback when an HTTPS certificate is determined to be available for the resource. This is used to conditionally update endpoint URI schemes or perform other HTTPS-related configuration at startup. WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionats export Waits for the dependency resource to enter the Running state before starting the resource.
WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)extensionats export Waits for the dependency resource to enter the Running state before starting the resource.
WaitForCompletion(IResourceBuilder<T>, IResourceBuilder<IResource>, int)extensionats export Waits for the dependency resource to enter the Exited or Finished state before starting the resource.
WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionats export Waits for the dependency resource to enter the Running state before starting the resource.
WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)extensionats export Waits for the dependency resource to enter the Running state before starting the resource.
WithArgs(IResourceBuilder<T>, string[])extensionats export Adds arguments to be passed to a resource that supports arguments when it is launched.
WithArgs(IResourceBuilder<T>, object[])extensionats ignored Adds arguments to be passed to a resource that supports arguments when it is launched.
WithArgs(IResourceBuilder<T>, Action<CommandLineArgsCallbackContext>)extensionats export Adds a callback to be executed with a list of command-line arguments when a resource is started.
WithArgs(IResourceBuilder<T>, Func<CommandLineArgsCallbackContext, Task>)extensionats export Adds an asynchronous callback to be executed with a list of command-line arguments when a resource is started.
WithCertificateAuthorityCollection(IResourceBuilder<TResource>, IResourceBuilder<CertificateAuthorityCollection>)extensionats ignoredIResourceBuilder<TResource> Adds a
CertificateAuthorityCollectionAnnotation to the resource annotations to associate a certificate authority collection with the resource. This is used to configure additional trusted certificate authorities for the resource. Custom certificate trust is only applied in run mode; in publish mode resources will use their default certificate trust behavior. WithCertificateTrustConfiguration(IResourceBuilder<TResource>, Func<CertificateTrustConfigurationCallbackAnnotationContext, Task>)extensionats ignoredIResourceBuilder<TResource> Adds a
CertificateTrustConfigurationCallbackAnnotation to the resource annotations to associate a callback that is invoked when a resource needs to configure itself for custom certificate trust. May be called multiple times to register additional callbacks to append additional configuration. Custom certificate trust is only applied in run mode; in publish mode resources will use their default certificate trust behavior. WithCertificateTrustScope(IResourceBuilder<TResource>, CertificateTrustScope)extensionats exportIResourceBuilder<TResource> Sets the
CertificateTrustScope for custom certificate authorities associated with the resource. The scope specifies how custom certificate authorities should be applied to a resource at run time in local development scenarios. Custom certificate trust is only applied in run mode; in publish mode resources will use their default certificate trust behavior. WithChildRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionats export Adds a
ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. WithChildRelationship(IResourceBuilder<T>, IResource)extensionats ignored Adds a
ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, CommandOptions?)extensionats export Adds a
ResourceCommandAnnotation to the resource annotations to add a resource command. WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, Func<UpdateCommandStateContext, ResourceCommandState>, string?, object?, string?, string?, IconVariant?, bool)extensionobsolete Adds a
ResourceCommandAnnotation to the resource annotations to add a resource command. WithComputeEnvironment(IResourceBuilder<T>, IResourceBuilder<IComputeEnvironmentResource>)extensionats ignored Configures the compute environment for the compute resource.
WithConnectionProperty(IResourceBuilder<T>, string, ReferenceExpression)extensionats export Adds a connection property annotation to the resource being built. Any resource referencing this resource will get this connection property included in its environment variables.
WithConnectionProperty(IResourceBuilder<T>, string, string)extensionats export Adds a connection property annotation to the resource being built. Any resource referencing this resource will get this connection property included in its environment variables.
WithConnectionStringRedirection(IResourceBuilder<T>, IResourceWithConnectionString)extensionats ignored Registers a callback which is invoked when a connection string is requested for a resource.
WithContainerFilesSource(IResourceBuilder<T>, string)extensionats export Adds a container files source annotation to the resource being built, specifying the path to the container files source.
WithDebugSupport(IResourceBuilder<T>, Func<string, TLaunchConfiguration>, string, Action<CommandLineArgsCallbackContext>)extensionexperimentalats ignored Adds support for debugging the resource in VS Code when running in an extension host.
WithDeveloperCertificateTrust(IResourceBuilder<TResource>, bool)extensionats exportIResourceBuilder<TResource> Indicates whether developer certificates should be treated as trusted certificate authorities for the resource at run time. Currently this indicates trust for the ASP.NET Core developer certificate. The developer certificate will only be trusted when running in local development scenarios; in publish mode resources will use their default certificate trust.
WithEndpoint(IResourceBuilder<T>, string, Action<EndpointAnnotation>, bool)extensionats ignored Changes an existing endpoint or creates a new endpoint if it doesn't exist and invokes callback to modify the defaults.
WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?, ProtocolType?)extensionats export Exposes an endpoint on a resource. A reference to this endpoint can be retrieved using
ResourceBuilderExtensions.GetEndpoint. The endpoint name will be the scheme name if not specified. WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?)extensionats ignored Exposes an endpoint on a resource. This endpoint reference can be retrieved using
ResourceBuilderExtensions.GetEndpoint. The endpoint name will be the scheme name if not specified. WithEnvironment(IResourceBuilder<T>, string, string?)extensionats ignored Adds an environment variable to the resource.
WithEnvironment(IResourceBuilder<T>, string, ExpressionInterpolatedStringHandler)extensionats ignored Adds an environment variable to the resource.
WithEnvironment(IResourceBuilder<T>, string, ReferenceExpression)extensionats ignored Adds an environment variable to the resource with a reference expression value.
WithEnvironment(IResourceBuilder<T>, string, Func<string>)extensionats ignored Adds an environment variable to the resource.
WithEnvironment(IResourceBuilder<T>, Action<EnvironmentCallbackContext>)extensionats ignored Allows for the population of environment variables on a resource.
WithEnvironment(IResourceBuilder<T>, Func<EnvironmentCallbackContext, Task>)extensionats export Allows for the population of environment variables on a resource.
WithEnvironment(IResourceBuilder<T>, string, EndpointReference)extensionats export Adds an environment variable to the resource with the endpoint for
endpointReference. WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ExternalServiceResource>)extensionats ignored Adds an environment variable to the resource with the URL from the
ExternalServiceResource. WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ParameterResource>)extensionats export Adds an environment variable to the resource with the value from
parameter. WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<IResourceWithConnectionString>)extensionats export Adds an environment variable to the resource with the connection string from the referenced resource.
WithEnvironment(IResourceBuilder<T>, string, TValue)extensionats ignored Adds an environment variable to the resource with a value that implements both
IValueProvider and IManifestExpressionProvider. WithExplicitStart(IResourceBuilder<T>)extensionats export Adds a
ExplicitStartupAnnotation annotation to the resource so it doesn't automatically start with the app host startup. WithExternalHttpEndpoints(IResourceBuilder<T>)extensionats export Marks existing http or https endpoints on a resource as external.
WithHealthCheck(IResourceBuilder<T>, string)extensionats export Adds a
HealthCheckAnnotation to the resource annotations to associate a resource with a named health check managed by the health check service. WithHttpCommand(IResourceBuilder<TResource>, string, string, string?, string?, HttpCommandOptions?)extensionats ignoredIResourceBuilder<TResource> Adds a command to the resource that when invoked sends an HTTP request to the specified endpoint and path.
WithHttpCommand(IResourceBuilder<TResource>, string, string, Func<EndpointReference>, string?, HttpCommandOptions?)extensionats ignoredIResourceBuilder<TResource> Adds a command to the resource that when invoked sends an HTTP request to the specified endpoint and path.
WithHttpEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool)extensionats export Exposes an HTTP endpoint on a resource. This endpoint reference can be retrieved using
ResourceBuilderExtensions.GetEndpoint. The endpoint name will be "http" if not specified. WithHttpHealthCheck(IResourceBuilder<T>, string?, int?, string?)extensionats export Adds a health check to the resource which is mapped to a specific endpoint.
WithHttpHealthCheck(IResourceBuilder<T>, Func<EndpointReference>, string?, int?)extensionats ignored Adds a health check to the resource which is mapped to a specific endpoint.
WithHttpProbe(IResourceBuilder<T>, ProbeType, string?, int?, int?, int?, int?, int?, string?)extensionexperimentalats ignored Adds a HTTP probe to the resource.
WithHttpProbe(IResourceBuilder<T>, ProbeType, Func<EndpointReference>, string?, int?, int?, int?, int?, int?)extensionexperimentalats ignored Adds a HTTP probe to the resource.
WithHttpsCertificate(IResourceBuilder<TResource>, X509Certificate2, IResourceBuilder<ParameterResource>)extensionexperimentalats ignoredIResourceBuilder<TResource> Adds a
HttpsCertificateAnnotation to the resource annotations to associate an X.509 certificate key pair with the resource. This is used to configure the certificate presented by the resource for HTTPS/TLS endpoints. WithHttpsCertificateConfiguration(IResourceBuilder<TResource>, Func<HttpsCertificateConfigurationCallbackAnnotationContext, Task>)extensionexperimentalats ignoredIResourceBuilder<TResource> Adds a callback that allows configuring the resource to use a specific HTTPS/TLS certificate key pair for server authentication.
WithHttpsDeveloperCertificate(IResourceBuilder<TResource>, IResourceBuilder<ParameterResource>)extensionexperimentalats exportIResourceBuilder<TResource> Indicates that a resource should use the developer certificate key pair for HTTPS endpoints at run time. Currently this indicates use of the ASP.NET Core developer certificate. The developer certificate will only be used when running in local development scenarios; in publish mode resources will use their default certificate configuration.
WithHttpsEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool)extensionats export Exposes an HTTPS endpoint on a resource. This endpoint reference can be retrieved using
ResourceBuilderExtensions.GetEndpoint. The endpoint name will be "https" if not specified. WithHttpsHealthCheck(IResourceBuilder<T>, string?, int?, string?)extensionobsolete Adds a health check to the resource which is mapped to a specific endpoint.
WithIconName(IResourceBuilder<T>, string, IconVariant)extensionats export Specifies the icon to use when displaying the resource in the dashboard.
WithImagePushOptions(IResourceBuilder<T>, Action<ContainerImagePushOptionsCallbackContext>)extensionexperimentalats ignored Adds a callback to configure container image push options for the resource.
WithImagePushOptions(IResourceBuilder<T>, Func<ContainerImagePushOptionsCallbackContext, Task>)extensionexperimentalats ignored Adds an asynchronous callback to configure container image push options for the resource.
WithManifestPublishingCallback(IResourceBuilder<T>, Action<ManifestPublishingContext>)extensionats ignored Registers a callback which is invoked when manifest is generated for the app model.
WithManifestPublishingCallback(IResourceBuilder<T>, Func<ManifestPublishingContext, Task>)extensionats ignored Registers an async callback which is invoked when manifest is generated for the app model.
WithoutHttpsCertificate(IResourceBuilder<TResource>)extensionexperimentalats exportIResourceBuilder<TResource> Disable HTTPS/TLS server certificate configuration for the resource. No HTTPS/TLS termination configuration will be applied.
WithParentRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionats export Adds a
ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. WithParentRelationship(IResourceBuilder<T>, IResource)extensionats ignored Adds a
ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, string?, bool)extensionats ignoredIResourceBuilder<TDestination> 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 IResourceWithConnectionString.GetConnectionStringAsync.
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(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>)extensionats ignoredIResourceBuilder<TDestination> Injects service discovery and 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
ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{sourceResourceName}__{endpointScheme}__{endpointIndex}={uriString}" for .NET service discovery, or "{RESOURCE_ENDPOINT}={uri}" for endpoint injection. WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>, string)extensionats ignoredIResourceBuilder<TDestination> Injects service discovery and 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
ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{name}__{endpointScheme}__{endpointIndex}={uriString}" for .NET service discovery, or "{name}_{ENDPOINT}={uri}" for endpoint injection. WithReference(IResourceBuilder<TDestination>, string, Uri)extensionats exportIResourceBuilder<TDestination> 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
ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{name}__default__0={uri}" for .NET service discovery, or "{name}={uri}" for endpoint injection. WithReference(IResourceBuilder<TDestination>, IResourceBuilder<ExternalServiceResource>)extensionats exportIResourceBuilder<TDestination> Injects service discovery information as environment variables from the
ExternalServiceResource 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(IResourceBuilder<TDestination>, EndpointReference)extensionats exportIResourceBuilder<TDestination> Injects service discovery and endpoint information from the specified endpoint into the project resource using the source resource's name as the service name. Each endpoint uri will be injected using the format defined by the
ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{name}__{endpointScheme}__{endpointIndex}={uriString}" for .NET service discovery, or "{NAME}_{ENDPOINT}={uri}" for endpoint injection. WithReferenceEnvironment(IResourceBuilder<TDestination>, ReferenceEnvironmentInjectionFlags)extensionats ignoredIResourceBuilder<TDestination> Configures how information is injected into environment variables when the resource references other resources.
WithReferenceRelationship(IResourceBuilder<T>, IResource)extensionats ignored Adds a
ResourceRelationshipAnnotation to the resource annotations to add a reference to another resource. WithReferenceRelationship(IResourceBuilder<T>, ReferenceExpression)extensionats ignored Walks the reference expression and adds
ResourceRelationshipAnnotation s for all resources found in the expression. WithReferenceRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionats ignored Adds a
ResourceRelationshipAnnotation to the resource annotations to add a reference to another resource. WithRelationship(IResourceBuilder<T>, IResource, string)extensionats ignored Adds a
ResourceRelationshipAnnotation to the resource annotations to add a relationship. WithRemoteImageName(IResourceBuilder<T>, string)extensionexperimentalats export Sets the remote image name (without registry endpoint or tag) for container push operations.
WithRemoteImageTag(IResourceBuilder<T>, string)extensionexperimentalats export Sets the remote image tag for container push operations.
WithUrl(IResourceBuilder<T>, string, string?)extensionats export Adds a URL to be displayed for the resource.
WithUrl(IResourceBuilder<T>, ExpressionInterpolatedStringHandler, string?)extensionats ignored Adds a URL to be displayed for the resource.
WithUrl(IResourceBuilder<T>, ReferenceExpression, string?)extensionats export Adds a URL to be displayed for the resource.
WithUrlForEndpoint(IResourceBuilder<T>, string, Action<ResourceUrlAnnotation>)extensionats export Registers a callback to update the URL displayed for the endpoint with the specified name.
WithUrlForEndpoint(IResourceBuilder<T>, string, Func<EndpointReference, ResourceUrlAnnotation>)extensionats export Registers a callback to add a URL for the endpoint with the specified name.
WithUrls(IResourceBuilder<T>, Action<ResourceUrlsCallbackContext>)extensionats export Registers a callback to customize the URLs displayed for the resource.
WithUrls(IResourceBuilder<T>, Func<ResourceUrlsCallbackContext, Task>)extensionats export Registers an async callback to customize the URLs displayed for the resource.