ResourceBuilderExtensions
Class static net10.0
Provides extension methods for configuring resources with environment variables.
namespace Aspire.Hosting;
public static class ResourceBuilderExtensions{ // ...} 88 members
Methods88
Section titled MethodsAsHttp2Service(IResourceBuilder<T>)extension 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>)extension Removes any container files source annotation from the resource being built.
ExcludeFromManifest(IResourceBuilder<T>)extension Excludes a resource from being published to the manifest.
ExcludeFromMcp(IResourceBuilder<T>)extension 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)extension Retrieves the value of a specified connection property from the resource's connection properties.
GetEndpoint(IResourceBuilder<T>, string, NetworkIdentifier)extension 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)extension 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)extension Configures the resource to copy container files from the specified source resource during publishing.
WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>)extension Waits for the dependency resource to enter the Running state before starting the resource.
WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)extension Waits for the dependency resource to enter the Running state before starting the resource.
WaitForCompletion(IResourceBuilder<T>, IResourceBuilder<IResource>, int)extension Waits for the dependency resource to enter the Exited or Finished state before starting the resource.
WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>)extension Waits for the dependency resource to enter the Running state before starting the resource.
WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)extension Waits for the dependency resource to enter the Running state before starting the resource.
WithArgs(IResourceBuilder<T>, string[])extension Adds arguments to be passed to a resource that supports arguments when it is launched.
WithArgs(IResourceBuilder<T>, object[])extension Adds arguments to be passed to a resource that supports arguments when it is launched.
WithArgs(IResourceBuilder<T>, Action<CommandLineArgsCallbackContext>)extension Adds a callback to be executed with a list of command-line arguments when a resource is started.
WithArgs(IResourceBuilder<T>, Func<CommandLineArgsCallbackContext, Task>)extension Adds an asynchronous callback to be executed with a list of command-line arguments when a resource is started.
WithCertificateAuthorityCollection(IResourceBuilder<TResource>, IResourceBuilder<CertificateAuthorityCollection>)extensionIResourceBuilder<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>)extensionIResourceBuilder<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)extensionIResourceBuilder<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>)extension Adds a
ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. WithChildRelationship(IResourceBuilder<T>, IResource)extension Adds a
ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, CommandOptions?)extension 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>)extension Configures the compute environment for the compute resource.
WithConnectionProperty(IResourceBuilder<T>, string, ReferenceExpression)extension 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)extension 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)extension Registers a callback which is invoked when a connection string is requested for a resource.
WithContainerFilesSource(IResourceBuilder<T>, string)extension 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>)extensionexperimental Adds support for debugging the resource in VS Code when running in an extension host.
WithDeveloperCertificateTrust(IResourceBuilder<TResource>, bool)extensionIResourceBuilder<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)extension 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?)extension 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?)extension 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?)extension Adds an environment variable to the resource.
WithEnvironment(IResourceBuilder<T>, string, ExpressionInterpolatedStringHandler)extension Adds an environment variable to the resource.
WithEnvironment(IResourceBuilder<T>, string, ReferenceExpression)extension Adds an environment variable to the resource.
WithEnvironment(IResourceBuilder<T>, string, Func<string>)extension Adds an environment variable to the resource.
WithEnvironment(IResourceBuilder<T>, Action<EnvironmentCallbackContext>)extension Allows for the population of environment variables on a resource.
WithEnvironment(IResourceBuilder<T>, Func<EnvironmentCallbackContext, Task>)extension Allows for the population of environment variables on a resource.
WithEnvironment(IResourceBuilder<T>, string, EndpointReference)extension Adds an environment variable to the resource with the endpoint for
endpointReference. WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ExternalServiceResource>)extension Adds an environment variable to the resource with the URL from the
ExternalServiceResource. WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ParameterResource>)extension Adds an environment variable to the resource with the value from
parameter. WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<IResourceWithConnectionString>)extension Adds an environment variable to the resource with the connection string from the referenced resource.
WithEnvironment(IResourceBuilder<T>, string, TValue)extension Adds an environment variable to the resource with a value that implements both
IValueProvider and IManifestExpressionProvider. WithExplicitStart(IResourceBuilder<T>)extension Adds a
ExplicitStartupAnnotation annotation to the resource so it doesn't automatically start with the app host startup. WithExternalHttpEndpoints(IResourceBuilder<T>)extension Marks existing http or https endpoints on a resource as external.
WithHealthCheck(IResourceBuilder<T>, string)extension 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?)extensionIResourceBuilder<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?)extensionIResourceBuilder<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)extension 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?)extension Adds a health check to the resource which is mapped to a specific endpoint.
WithHttpHealthCheck(IResourceBuilder<T>, Func<EndpointReference>, string?, int?)extension 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?)extensionexperimental Adds a HTTP probe to the resource.
WithHttpProbe(IResourceBuilder<T>, ProbeType, Func<EndpointReference>, string?, int?, int?, int?, int?, int?)extensionexperimental Adds a HTTP probe to the resource.
WithHttpsCertificate(IResourceBuilder<TResource>, X509Certificate2, IResourceBuilder<ParameterResource>)extensionexperimentalIResourceBuilder<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>)extensionexperimentalIResourceBuilder<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>)extensionexperimentalIResourceBuilder<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)extension 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)extension Specifies the icon to use when displaying the resource in the dashboard.
WithImagePushOptions(IResourceBuilder<T>, Action<ContainerImagePushOptionsCallbackContext>)extensionexperimental Adds a callback to configure container image push options for the resource.
WithImagePushOptions(IResourceBuilder<T>, Func<ContainerImagePushOptionsCallbackContext, Task>)extensionexperimental Adds an asynchronous callback to configure container image push options for the resource.
WithManifestPublishingCallback(IResourceBuilder<T>, Action<ManifestPublishingContext>)extension Registers a callback which is invoked when manifest is generated for the app model.
WithManifestPublishingCallback(IResourceBuilder<T>, Func<ManifestPublishingContext, Task>)extension Registers an async callback which is invoked when manifest is generated for the app model.
WithoutHttpsCertificate(IResourceBuilder<TResource>)extensionexperimentalIResourceBuilder<TResource> Disable HTTPS/TLS server certificate configuration for the resource. No HTTPS/TLS termination configuration will be applied.
WithParentRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extension Adds a
ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. WithParentRelationship(IResourceBuilder<T>, IResource)extension Adds a
ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, string?, bool)extensionIResourceBuilder<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>)extensionIResourceBuilder<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}__{endpointName}__{endpointIndex}={uriString}" for .NET service discovery, or "{RESOURCE_ENDPOINT}={uri}" for endpoint injection. WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>, string)extensionIResourceBuilder<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}__{endpointName}__{endpointIndex}={uriString}" for .NET service discovery, or "{name}_{ENDPOINT}={uri}" for endpoint injection. WithReference(IResourceBuilder<TDestination>, string, Uri)extensionIResourceBuilder<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>)extensionIResourceBuilder<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)extensionIResourceBuilder<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}__{endpointName}__{endpointIndex}={uriString}" for .NET service discovery, or "{NAME}_{ENDPOINT}={uri}" for endpoint injection. WithReferenceEnvironment(IResourceBuilder<TDestination>, ReferenceEnvironmentInjectionFlags)extensionIResourceBuilder<TDestination> Configures how information is injected into environment variables when the resource references other resources.
WithReferenceRelationship(IResourceBuilder<T>, IResource)extension Adds a
ResourceRelationshipAnnotation to the resource annotations to add a reference to another resource. WithReferenceRelationship(IResourceBuilder<T>, ReferenceExpression)extension Walks the reference expression and adds
ResourceRelationshipAnnotation s for all resources found in the expression. WithReferenceRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extension Adds a
ResourceRelationshipAnnotation to the resource annotations to add a reference to another resource. WithRelationship(IResourceBuilder<T>, IResource, string)extension Adds a
ResourceRelationshipAnnotation to the resource annotations to add a relationship. WithRemoteImageName(IResourceBuilder<T>, string)extensionexperimental Sets the remote image name (without registry endpoint or tag) for container push operations.
WithRemoteImageTag(IResourceBuilder<T>, string)extensionexperimental Sets the remote image tag for container push operations.
WithUrl(IResourceBuilder<T>, string, string?)extension Adds a URL to be displayed for the resource.
WithUrl(IResourceBuilder<T>, ExpressionInterpolatedStringHandler, string?)extension Adds a URL to be displayed for the resource.
WithUrl(IResourceBuilder<T>, ReferenceExpression, string?)extension Adds a URL to be displayed for the resource.
WithUrlForEndpoint(IResourceBuilder<T>, string, Action<ResourceUrlAnnotation>)extension Registers a callback to update the URL displayed for the endpoint with the specified name.
WithUrlForEndpoint(IResourceBuilder<T>, string, Func<EndpointReference, ResourceUrlAnnotation>)extension Registers a callback to add a URL for the endpoint with the specified name.
WithUrls(IResourceBuilder<T>, Action<ResourceUrlsCallbackContext>)extension Registers a callback to customize the URLs displayed for the resource.
WithUrls(IResourceBuilder<T>, Func<ResourceUrlsCallbackContext, Task>)extension Registers an async callback to customize the URLs displayed for the resource.