ResourceBuilderExtensions Methods
AsHttp2Service(IResourceBuilder<T>)Section titled AsHttp2Service(IResourceBuilder<T>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> AsHttp2Service<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.ClearContainerFilesSources(IResourceBuilder<T>)Section titled ClearContainerFilesSources(IResourceBuilder<T>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> ClearContainerFilesSources<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder to which the container files source annotations should be removed. Cannot be null.Returns
IResourceBuilder<T>The resource builder instance with the container files source annotation applied.ExcludeFromManifest(IResourceBuilder<T>)Section titled ExcludeFromManifest(IResourceBuilder<T>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> ExcludeFromManifest<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIResourceBuilder<T>The resource to exclude.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.ExcludeFromMcp(IResourceBuilder<T>)Section titled ExcludeFromMcp(IResourceBuilder<T>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> ExcludeFromMcp<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.GetConnectionProperty(IResourceWithConnectionString, string)Section titled GetConnectionProperty(IResourceWithConnectionString, string)extensionReferenceExpressionpublic static class ResourceBuilderExtensions{ public static ReferenceExpression GetConnectionProperty( this IResourceWithConnectionString resource, string key) { // ... }}Parameters
resourceIResourceWithConnectionStringThe resource that provides the connection properties. Cannot be null.keystringThe key of the connection property to retrieve. Cannot be null.Returns
ReferenceExpressionThe value associated with the specified connection property key.Remarks
GetEndpoint(IResourceBuilder<T>, string, NetworkIdentifier)Section titled GetEndpoint(IResourceBuilder<T>, string, NetworkIdentifier)extensionEndpointReferenceEndpointReference 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. public static class ResourceBuilderExtensions{ public static EndpointReference GetEndpoint<T>( this IResourceBuilder<T> builder, string name, NetworkIdentifier contextNetworkID) { // ... }}Parameters
builderIResourceBuilder<T>The the resource builder.namestringThe name of the endpoint.contextNetworkIDNetworkIdentifierThe network context in which to resolve the endpoint. If null, localhost (loopback) network context will be used.Returns
EndpointReferenceAn EndpointReference that can be used to resolve the address of the endpoint after resource allocation has occurred.Remarks
GetEndpoint(IResourceBuilder<T>, string)Section titled GetEndpoint(IResourceBuilder<T>, string)extensionEndpointReferenceEndpointReference 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. public static class ResourceBuilderExtensions{ public static EndpointReference GetEndpoint<T>( this IResourceBuilder<T> builder, string name) { // ... }}Parameters
builderIResourceBuilder<T>The the resource builder.namestringThe name of the endpoint.Returns
EndpointReferenceAn EndpointReference that can be used to resolve the address of the endpoint after resource allocation has occurred.PublishWithContainerFiles(IResourceBuilder<T>, IResourceBuilder<IResourceWithContainerFiles>, string)Section titled PublishWithContainerFiles(IResourceBuilder<T>, IResourceBuilder<IResourceWithContainerFiles>, string)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> PublishWithContainerFiles<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResourceWithContainerFiles> source, string destinationPath) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder to which container files will be copied to.sourceIResourceBuilder<IResourceWithContainerFiles>The resource which contains the container files to be copied.destinationPathstringThe destination path within the resource's container where the files will be copied.SubscribeHttpsEndpointsUpdate(IResourceBuilder<TResource>, Action<HttpsEndpointUpdateCallbackContext>)Section titled SubscribeHttpsEndpointsUpdate(IResourceBuilder<TResource>, Action<HttpsEndpointUpdateCallbackContext>)extensionIResourceBuilder<TResource>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. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> SubscribeHttpsEndpointsUpdate<TResource>( this IResourceBuilder<TResource> builder, Action<HttpsEndpointUpdateCallbackContext> callback) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.callbackAction<HttpsEndpointUpdateCallbackContext>The callback to invoke when HTTPS is enabled. Receives an HttpsEndpointUpdateCallbackContext providing access to the service provider, resource, and application model.Returns
IResourceBuilder<TResource>The updated resource builder.Remarks
- No
HttpsCertificateAnnotationis present and theIDeveloperCertificateServiceindicates that HTTPS should be used by default. - An
HttpsCertificateAnnotationis present that requests a developer certificate or provides a custom certificate.
builder.SubscribeHttpsEndpointsUpdate(ctx =>{ builder.WithEndpoint("http", ep => ep.UriScheme = "https");});This method is not available in polyglot app hosts.
WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>)Section titled WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitFor<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the resource that will be waiting.dependencyIResourceBuilder<IResource>The resource builder for the dependency resource.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method is useful when a resource should wait until another has started running. This can help reduce errors in logs during local development where dependency resources.
Some resources automatically register health checks with the application host container. For these resources, calling ResourceBuilderExtensions.WaitFor also results in the resource being blocked from starting until the health checks associated with the dependency resource return HealthStatus.Healthy.
The ResourceBuilderExtensions.WithHealthCheck method can be used to associate additional health checks with a resource.
var builder = DistributedApplication.CreateBuilder(args);var messaging = builder.AddRabbitMQ("messaging");builder.AddProject<Projects.MyApp>("myapp") .WithReference(messaging) .WaitFor(messaging);WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)Section titled WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitFor<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency, WaitBehavior waitBehavior) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the resource that will be waiting.dependencyIResourceBuilder<IResource>The resource builder for the dependency resource.waitBehaviorWaitBehaviorThe wait behavior to use.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method is useful when a resource should wait until another has started running. This can help reduce errors in logs during local development where dependency resources.
Some resources automatically register health checks with the application host container. For these resources, calling ResourceBuilderExtensions.WaitFor also results in the resource being blocked from starting until the health checks associated with the dependency resource return HealthStatus.Healthy.
The ResourceBuilderExtensions.WithHealthCheck method can be used to associate additional health checks with a resource.
The waitBehavior parameter can be used to control the behavior of the wait operation. When WaitBehavior.WaitOnResourceUnavailable is specified, the wait operation will continue to wait until the resource becomes healthy. This is the default behavior with the ResourceBuilderExtensions.WaitFor overload.
When WaitBehavior.StopOnResourceUnavailable is specified, the wait operation will throw a DistributedApplicationException if the resource enters an unavailable state.
var builder = DistributedApplication.CreateBuilder(args);var messaging = builder.AddRabbitMQ("messaging");builder.AddProject<Projects.MyApp>("myapp") .WithReference(messaging) .WaitFor(messaging, WaitBehavior.StopOnResourceUnavailable);WaitForCompletion(IResourceBuilder<T>, IResourceBuilder<IResource>, int)Section titled WaitForCompletion(IResourceBuilder<T>, IResourceBuilder<IResource>, int)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitForCompletion<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency, int exitCode = 0) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the resource that will be waiting.dependencyIResourceBuilder<IResource>The resource builder for the dependency resource.exitCodeintoptionalThe exit code which is interpreted as successful.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method is useful when a resource should wait until another has completed. A common usage pattern would be to include a console application that initializes the database schema or performs other one off initialization tasks.
Note that this method has no impact at deployment time and only works for local development.
Wait for database initialization app to complete running.var builder = DistributedApplication.CreateBuilder(args);var pgsql = builder.AddPostgres("postgres");var dbprep = builder.AddProject<Projects.DbPrepApp>("dbprep") .WithReference(pgsql);builder.AddProject<Projects.DatabasePrepTool>("dbpreptool") .WithReference(pgsql) .WaitForCompletion(dbprep);WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>)Section titled WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitForStart<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the resource that will be waiting.dependencyIResourceBuilder<IResource>The resource builder for the dependency resource.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method is useful when a resource should wait until another has started running but doesn't need to wait for health checks to pass. This can help enable initialization scenarios where services need to start before health checks can pass.
Unlike ResourceBuilderExtensions.WaitFor, this method only waits for the dependency resource to enter the Running state and ignores any health check annotations associated with the dependency resource.
var builder = DistributedApplication.CreateBuilder(args);var messaging = builder.AddRabbitMQ("messaging");builder.AddProject<Projects.MyApp>("myapp") .WithReference(messaging) .WaitForStart(messaging);WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)Section titled WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitForStart<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency, WaitBehavior waitBehavior) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for the resource that will be waiting.dependencyIResourceBuilder<IResource>The resource builder for the dependency resource.waitBehaviorWaitBehaviorThe wait behavior to use.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method is useful when a resource should wait until another has started running but doesn't need to wait for health checks to pass. This can help enable initialization scenarios where services need to start before health checks can pass.
Unlike ResourceBuilderExtensions.WaitFor, this method only waits for the dependency resource to enter the Running state and ignores any health check annotations associated with the dependency resource.
The waitBehavior parameter can be used to control the behavior of the wait operation. When WaitBehavior.WaitOnResourceUnavailable is specified, the wait operation will continue to wait until the resource enters the Running state. This is the default behavior with the ResourceBuilderExtensions.WaitForStart overload.
When WaitBehavior.StopOnResourceUnavailable is specified, the wait operation will throw a DistributedApplicationException if the resource enters an unavailable state.
var builder = DistributedApplication.CreateBuilder(args);var messaging = builder.AddRabbitMQ("messaging");builder.AddProject<Projects.MyApp>("myapp") .WithReference(messaging) .WaitForStart(messaging, WaitBehavior.StopOnResourceUnavailable);WithArgs(IResourceBuilder<T>, string[])Section titled WithArgs(IResourceBuilder<T>, string[])extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithArgs<T>( this IResourceBuilder<T> builder, params string[] args) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for a resource implementing IResourceWithArgs.argsstring[]The arguments to be passed to the resource when it is started.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithArgs(IResourceBuilder<T>, object[])Section titled WithArgs(IResourceBuilder<T>, object[])extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithArgs<T>( this IResourceBuilder<T> builder, params object[] args) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for a resource implementing IResourceWithArgs.argsobject[]The arguments to be passed to the resource when it is started.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
WithArgs(IResourceBuilder<T>, Action<CommandLineArgsCallbackContext>)Section titled WithArgs(IResourceBuilder<T>, Action<CommandLineArgsCallbackContext>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithArgs<T>( this IResourceBuilder<T> builder, Action<CommandLineArgsCallbackContext> callback) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for a resource implementing IResourceWithArgs.callbackAction<CommandLineArgsCallbackContext>A callback that allows for deferred execution for computing arguments. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithArgs(IResourceBuilder<T>, Func<CommandLineArgsCallbackContext, Task>)Section titled WithArgs(IResourceBuilder<T>, Func<CommandLineArgsCallbackContext, Task>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithArgs<T>( this IResourceBuilder<T> builder, Func<CommandLineArgsCallbackContext, Task> callback) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder for a resource implementing IResourceWithArgs.callbackFunc<CommandLineArgsCallbackContext, Task>An asynchronous callback that allows for deferred execution for computing arguments. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithCertificateAuthorityCollection(IResourceBuilder<TResource>, IResourceBuilder<CertificateAuthorityCollection>)Section titled WithCertificateAuthorityCollection(IResourceBuilder<TResource>, IResourceBuilder<CertificateAuthorityCollection>)extensionIResourceBuilder<TResource>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. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithCertificateAuthorityCollection<TResource>( this IResourceBuilder<TResource> builder, IResourceBuilder<CertificateAuthorityCollection> certificateAuthorityCollection) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.certificateAuthorityCollectionIResourceBuilder<CertificateAuthorityCollection>Additional certificates in a CertificateAuthorityCollection to treat as trusted certificate authorities for the resource.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
var caCollection = builder.AddCertificateAuthorityCollection("my-cas") .WithCertificatesFromFile("../my-ca.pem");
var container = builder.AddContainer("my-service", "my-service:latest") .WithCertificateAuthorityCollection(caCollection);This method is not available in polyglot app hosts.
WithCertificateTrustConfiguration(IResourceBuilder<TResource>, Func<CertificateTrustConfigurationCallbackAnnotationContext, Task>)Section titled WithCertificateTrustConfiguration(IResourceBuilder<TResource>, Func<CertificateTrustConfigurationCallbackAnnotationContext, Task>)extensionIResourceBuilder<TResource>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. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithCertificateTrustConfiguration<TResource>( this IResourceBuilder<TResource> builder, Func<CertificateTrustConfigurationCallbackAnnotationContext, Task> callback) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.callbackFunc<CertificateTrustConfigurationCallbackAnnotationContext, Task>The callback to invoke when a resource needs to configure itself for custom certificate trust.Returns
IResourceBuilder<TResource>The updated resource builder.Remarks
var container = builder.AddContainer("my-service", "my-service:latest") .WithCertificateTrustConfigurationCallback(ctx => { if (ctx.Scope != CertificateTrustScope.Append) { ctx .EnvironmentVariables["CUSTOM_CERTS_BUNDLE_ENV"] = ctx .CertificateBundlePath; } ctx .EnvironmentVariables["ADDITIONAL_CERTS_DIR_ENV"] = ctx .CertificateDirectoriesPath; });This method is not available in polyglot app hosts.
WithCertificateTrustScope(IResourceBuilder<TResource>, CertificateTrustScope)Section titled WithCertificateTrustScope(IResourceBuilder<TResource>, CertificateTrustScope)extensionIResourceBuilder<TResource>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. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithCertificateTrustScope<TResource>( this IResourceBuilder<TResource> builder, CertificateTrustScope scope) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.scopeCertificateTrustScopeThe scope to apply to custom certificate authorities associated with the resource.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
CertificateTrustScope.Append which means that custom certificate authorities should be appended to the default trusted certificate authorities for the resource. Setting the scope to CertificateTrustScope.Override indicates the set of certificates in referenced CertificateAuthorityCollection (and optionally Aspire developer certificiates) should be used as the exclusive source of trust for a resource. In all cases, this is a best effort implementation as not all resources support full customization of certificate trust. Set the scope for custom certificate authorities to override the default trusted certificate authorities for a container resource. var caCollection = builder.AddCertificateAuthorityCollection("my-cas") .WithCertificate(new X509Certificate2("my-ca.pem"));
var container = builder.AddContainer("my-service", "my-service:latest") .WithCertificateAuthorityCollection(caCollection) .WithCertificateTrustScope(CertificateTrustScope.Override);WithChildRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)Section titled WithChildRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIResourceBuilder<T>ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithChildRelationship<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> child) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.childIResourceBuilder<IResource>The child of builder.Returns
IResourceBuilder<T>A resource builder.Remarks
The WithChildRelationship method is used to add child relationships to the resource. Relationships are used to link resources together in UI.
var builder = DistributedApplication.CreateBuilder(args);
var parameter = builder.AddParameter("parameter");
var backend = builder.AddProject<Projects.Backend>("backend"); .WithChildRelationship(parameter);WithChildRelationship(IResourceBuilder<T>, IResource)Section titled WithChildRelationship(IResourceBuilder<T>, IResource)extensionIResourceBuilder<T>ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithChildRelationship<T>( this IResourceBuilder<T> builder, IResource child) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.childIResourceThe child of builder.Returns
IResourceBuilder<T>A resource builder.Remarks
The WithChildRelationship method is used to add child relationships to the resource. Relationships are used to link resources together in UI.
var builder = DistributedApplication.CreateBuilder(args);
var parameter = builder.AddParameter("parameter");
var backend = builder.AddProject<Projects.Backend>("backend"); .WithChildRelationship(parameter.Resource);This method is not available in polyglot app hosts. Use the IResourceBuilder overload instead.
WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, CommandOptions?)Section titled WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, CommandOptions?)extensionIResourceBuilder<T>ResourceCommandAnnotation to the resource annotations to add a resource command. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithCommand<T>( this IResourceBuilder<T> builder, string name, string displayName, Func<ExecuteCommandContext, Task<ExecuteCommandResult>> executeCommand, CommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the command. The name uniquely identifies the command.displayNamestringThe display name visible in UI.executeCommandFunc<ExecuteCommandContext, Task<ExecuteCommandResult>> A callback that is executed when the command is executed. The callback is run inside the Aspire host. The callback result is used to indicate success or failure in the UI. commandOptionsCommandOptions?optionalOptional configuration for the command.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
The WithCommand method is used to add commands to the resource. Commands are displayed in the dashboard and can be executed by a user using the dashboard UI.
When a command is executed, the executeCommand callback is called and is run inside the Aspire host.
WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, Func<UpdateCommandStateContext, ResourceCommandState>, string?, object?, string?, string?, IconVariant?, bool)Section titled WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, Func<UpdateCommandStateContext, ResourceCommandState>, string?, object?, string?, string?, IconVariant?, bool)extensionIResourceBuilder<T>ResourceCommandAnnotation to the resource annotations to add a resource command. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithCommand<T>( this IResourceBuilder<T> builder, string name, string displayName, Func<ExecuteCommandContext, Task<ExecuteCommandResult>> executeCommand, Func<UpdateCommandStateContext, ResourceCommandState>? updateState = null, string? displayDescription = null, object? parameter = null, string? confirmationMessage = null, string? iconName = null, IconVariant? iconVariant = null, bool isHighlighted = false) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the command. The name uniquely identifies the command.displayNamestringThe display name visible in UI.executeCommandFunc<ExecuteCommandContext, Task<ExecuteCommandResult>> A callback that is executed when the command is executed. The callback is run inside the Aspire host. The callback result is used to indicate success or failure in the UI. updateStateFunc<UpdateCommandStateContext, ResourceCommandState>optionalA callback that is used to update the command state. The callback is executed when the command's resource snapshot is updated.
If a callback isn't specified, the command is always enabled.
displayDescriptionstring?optional Optional description of the command, to be shown in the UI. Could be used as a tooltip. May be localized. parameterobject?optional Optional parameter that configures the command in some way. Clients must return any value provided by the server when invoking the command. confirmationMessagestring?optional When a confirmation message is specified, the UI will prompt with an OK/Cancel dialog and the confirmation message before starting the command. iconNamestring?optionalThe icon name for the command. The name should be a valid FluentUI icon name from https://aka.ms/fluentui-system-iconsiconVariantIconVariant?optionalThe icon variant.isHighlightedbooloptionalA flag indicating whether the command is highlighted in the UI.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
The WithCommand method is used to add commands to the resource. Commands are displayed in the dashboard and can be executed by a user using the dashboard UI.
When a command is executed, the executeCommand callback is called and is run inside the Aspire host.
WithComputeEnvironment(IResourceBuilder<T>, IResourceBuilder<IComputeEnvironmentResource>)Section titled WithComputeEnvironment(IResourceBuilder<T>, IResourceBuilder<IComputeEnvironmentResource>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithComputeEnvironment<T>( this IResourceBuilder<T> builder, IResourceBuilder<IComputeEnvironmentResource> computeEnvironmentResource) { // ... }}Parameters
builderIResourceBuilder<T>The compute resource builder.computeEnvironmentResourceIResourceBuilder<IComputeEnvironmentResource>The compute environment resource to associate with the compute resource.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
WithConnectionProperty(IResourceBuilder<T>, string, ReferenceExpression)Section titled WithConnectionProperty(IResourceBuilder<T>, string, ReferenceExpression)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithConnectionProperty<T>( this IResourceBuilder<T> builder, string name, ReferenceExpression value) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder to which the connection property annotation will be added. Cannot be null.namestringThe name of the connection property to annotate. Cannot be null.valueReferenceExpressionThe value of the connection property, specified as a reference expression.Returns
IResourceBuilder<T>The same resource builder instance with the connection property annotation applied.Remarks
WithConnectionProperty(IResourceBuilder<T>, string, string)Section titled WithConnectionProperty(IResourceBuilder<T>, string, string)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithConnectionProperty<T>( this IResourceBuilder<T> builder, string name, string value) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder to which the connection property will be added. Cannot be null.namestringThe name of the connection property to add. Cannot be null.valuestringThe value to assign to the connection property.Returns
IResourceBuilder<T>The same resource builder instance with the specified connection property annotation applied.WithConnectionStringRedirection(IResourceBuilder<T>, IResourceWithConnectionString)Section titled WithConnectionStringRedirection(IResourceBuilder<T>, IResourceWithConnectionString)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithConnectionStringRedirection<T>( this IResourceBuilder<T> builder, IResourceWithConnectionString resource) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.resourceIResourceWithConnectionStringResource to which connection string generation is redirected.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
WithContainerFilesSource(IResourceBuilder<T>, string)Section titled WithContainerFilesSource(IResourceBuilder<T>, string)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithContainerFilesSource<T>( this IResourceBuilder<T> builder, string sourcePath) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder to which the container files source annotation will be added. Cannot be null.sourcePathstringThe path to the container files source to associate with the resource. Cannot be null.Returns
IResourceBuilder<T>The resource builder instance with the container files source annotation applied.WithDebugSupport(IResourceBuilder<T>, Func<string, TLaunchConfiguration>, string, Action<CommandLineArgsCallbackContext>)Section titled WithDebugSupport(IResourceBuilder<T>, Func<string, TLaunchConfiguration>, string, Action<CommandLineArgsCallbackContext>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithDebugSupport<T, TLaunchConfiguration>( this IResourceBuilder<T> builder, Func<string, TLaunchConfiguration> launchConfigurationProducer, string launchConfigurationType, Action<CommandLineArgsCallbackContext>? argsCallback = null) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.launchConfigurationProducerFunc<string, TLaunchConfiguration>Launch configuration producer for the resource.launchConfigurationTypestringThe type of the resource.argsCallbackAction<CommandLineArgsCallbackContext>optionalOptional callback to add or modify command line arguments when running in an extension host. Useful if the entrypoint is usually provided as an argument to the resource executable.WithDeveloperCertificateTrust(IResourceBuilder<TResource>, bool)Section titled WithDeveloperCertificateTrust(IResourceBuilder<TResource>, bool)extensionIResourceBuilder<TResource>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithDeveloperCertificateTrust<TResource>( this IResourceBuilder<TResource> builder, bool trust) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.trustboolIndicates whether the developer certificate should be treated as trusted.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
var container = builder.AddContainer("my-service", "my-service:latest") .WithDeveloperCertificateTrust(false);var builder = DistributedApplication.CreateBuilder( new DistributedApplicationOptions(){ Args = args, TrustDeveloperCertificate = false,});var project = builder.AddProject<MyService>("my-service") .WithDeveloperCertificateTrust(true);WithEndpoint(IResourceBuilder<T>, string, Action<EndpointAnnotation>, bool)Section titled WithEndpoint(IResourceBuilder<T>, string, Action<EndpointAnnotation>, bool)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, string endpointName, Action<EndpointAnnotation> callback, bool createIfNotExists = true) { // ... }}Parameters
builderIResourceBuilder<T>Resource builder for resource with endpoints.endpointNamestringName of endpoint to change.callbackAction<EndpointAnnotation>Callback that modifies the endpoint.createIfNotExistsbooloptionalCreate endpoint if it does not exist.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
The ResourceBuilderExtensions.WithEndpoint method allows developers to mutate any aspect of an endpoint annotation. Note that changing one value does not automatically change other values to compatible/consistent values. For example setting the EndpointAnnotation.Protocol property of the endpoint annotation in the callback will not automatically change the EndpointAnnotation.UriScheme. All values should be set in the callback if the defaults are not acceptable.
var builder = DistributedApplication.Create(args);var container = builder.AddContainer("mycontainer", "myimage") .WithEndpoint("myendpoint", e => { e.Port = 9998; e.TargetPort = 9999; e.Protocol = ProtocolType.Udp; e.UriScheme = "udp"; });This method is not available in polyglot app hosts. Use the callback-based endpoint mutation export instead.
WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool?, bool?, ProtocolType?)Section titled WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool?, bool?, ProtocolType?)extensionIResourceBuilder<T>ResourceBuilderExtensions.GetEndpoint. The endpoint name will be the scheme name if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, int? port = null, int? targetPort = null, string? scheme = null, string? name = null, string? env = null, bool? isProxied = null, bool? isExternal = null, ProtocolType? protocol = null) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.portint?optionalAn optional port. This is the port that will be given to other resource to communicate with this resource.targetPortint?optionalThis is the port the resource is listening on. If the endpoint is used for the container, it is the container port.schemestring?optionalAn optional scheme e.g. (http/https). Defaults to the protocol argument if it is defined or "tcp" otherwise.namestring?optionalAn optional name of the endpoint. Defaults to the scheme name if not specified.envstring?optionalAn optional name of the environment variable that will be used to inject the targetPort. If the target port is null one will be dynamically generated and assigned to the environment variable.isProxiedbool?optionalSpecifies if the endpoint will be proxied by DCP. Defaults to null.isExternalbool?optionalIndicates that this endpoint should be exposed externally at publish time.protocolProtocolType?optionalNetwork protocol: TCP or UDP are supported today, others possibly in future.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
DistributedApplicationExceptionThrows an exception if an endpoint with the same name already exists on the specified resource.WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?, ProtocolType?)Section titled WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?, ProtocolType?)extensionIResourceBuilder<T>ResourceBuilderExtensions.GetEndpoint. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? scheme, string? name, string? env, bool isProxied, bool? isExternal, ProtocolType? protocol) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.portint?An optional port. This is the port that will be given to other resource to communicate with this resource.targetPortint?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.schemestring?An optional scheme e.g. (http/https). Defaults to the protocol argument if it is defined or "tcp" otherwise.namestring?An optional name of the endpoint. Defaults to the scheme name if not specified.envstring?An optional name of the environment variable that will be used to inject the targetPort. If the target port is null one will be dynamically generated and assigned to the environment variable.isProxiedboolSpecifies if the endpoint will be proxied by DCP.isExternalbool?Indicates that this endpoint should be exposed externally at publish time.protocolProtocolType?Network protocol: TCP or UDP are supported today, others possibly in future.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
DistributedApplicationExceptionThrows an exception if an endpoint with the same name already exists on the specified resource.Remarks
bool isProxied signature. New source that omits isProxied binds to the nullable overload where omission is represented as null. WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool?, bool?)Section titled WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool?, bool?)extensionIResourceBuilder<T>ResourceBuilderExtensions.GetEndpoint. The endpoint name will be the scheme name if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? scheme, string? name, string? env, bool? isProxied, bool? isExternal) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.portint?An optional port. This is the port that will be given to other resource to communicate with this resource.targetPortint?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.schemestring?An optional scheme e.g. (http/https). Defaults to "tcp" if not specified.namestring?An optional name of the endpoint. Defaults to the scheme name if not specified.envstring?An optional name of the environment variable that will be used to inject the targetPort. If the target port is null one will be dynamically generated and assigned to the environment variable.isProxiedbool?Specifies if the endpoint will be proxied by DCP. Defaults to null.isExternalbool?Indicates that this endpoint should be exposed externally at publish time.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
DistributedApplicationExceptionThrows an exception if an endpoint with the same name already exists on the specified resource.Remarks
This method is not available in polyglot app hosts. Use the overload with ProtocolType parameter instead.
If an endpoint with the same name already exists, the existing endpoint is updated with any non-null parameter values.
WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?)Section titled WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?)extensionIResourceBuilder<T>ResourceBuilderExtensions.GetEndpoint. The endpoint name will be the scheme name if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? scheme, string? name, string? env, bool isProxied, bool? isExternal) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.portint?An optional port. This is the port that will be given to other resource to communicate with this resource.targetPortint?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.schemestring?An optional scheme e.g. (http/https). Defaults to "tcp" if not specified.namestring?An optional name of the endpoint. Defaults to the scheme name if not specified.envstring?An optional name of the environment variable that will be used to inject the targetPort. If the target port is null one will be dynamically generated and assigned to the environment variable.isProxiedboolSpecifies if the endpoint will be proxied by DCP.isExternalbool?Indicates that this endpoint should be exposed externally at publish time.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
DistributedApplicationExceptionThrows an exception if an endpoint with the same name already exists on the specified resource.Remarks
bool isProxied signature. New source that omits isProxied binds to the nullable overload where omission is represented as null. WithEndpointProxySupport(IResourceBuilder<IResourceWithEndpoints>, bool)Section titled WithEndpointProxySupport(IResourceBuilder<IResourceWithEndpoints>, bool)extensionIResourceBuilder<IResourceWithEndpoints>false, endpoints belonging to the resource will ignore the configured proxy settings and run proxy-less. public static class ResourceBuilderExtensions{ public static IResourceBuilder<IResourceWithEndpoints> WithEndpointProxySupport( this IResourceBuilder<IResourceWithEndpoints> builder, bool proxyEnabled) { // ... }}Parameters
builderIResourceBuilder<IResourceWithEndpoints>The resource builder.proxyEnabledboolShould endpoints for the resource support using a proxy?Returns
IResourceBuilder<IResourceWithEndpoints>The resource builder.Remarks
WithEnvironment(IResourceBuilder<T>, string, string?)Section titled WithEnvironment(IResourceBuilder<T>, string, string?)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, string? value) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the environment variable.valuestring?The value of the environment variable.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithEnvironment(IResourceBuilder<T>, string, ExpressionInterpolatedStringHandler)Section titled WithEnvironment(IResourceBuilder<T>, string, ExpressionInterpolatedStringHandler)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, in ExpressionInterpolatedStringHandler value) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the environment variable.valueExpressionInterpolatedStringHandlerThe value of the environment variable.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
WithEnvironment(IResourceBuilder<T>, string, ReferenceExpression)Section titled WithEnvironment(IResourceBuilder<T>, string, ReferenceExpression)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, ReferenceExpression value) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the environment variable.valueReferenceExpressionA ReferenceExpression that will be evaluated at runtime.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This overload enables polyglot hosts to set environment variables using dynamic expressions that reference endpoints, parameters, and other value providers.
Usage from TypeScript:
WithEnvironment(IResourceBuilder<T>, string, Func<string>)Section titled WithEnvironment(IResourceBuilder<T>, string, Func<string>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, Func<string> callback) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the environment variable.callbackFunc<string>A callback that allows for deferred execution of a specific environment variable. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
WithEnvironment(IResourceBuilder<T>, Action<EnvironmentCallbackContext>)Section titled WithEnvironment(IResourceBuilder<T>, Action<EnvironmentCallbackContext>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, Action<EnvironmentCallbackContext> callback) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.callbackAction<EnvironmentCallbackContext>A callback that allows for deferred execution for computing many environment variables. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithEnvironment(IResourceBuilder<T>, Func<EnvironmentCallbackContext, Task>)Section titled WithEnvironment(IResourceBuilder<T>, Func<EnvironmentCallbackContext, Task>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, Func<EnvironmentCallbackContext, Task> callback) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.callbackFunc<EnvironmentCallbackContext, Task>A callback that allows for deferred execution for computing many environment variables. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithEnvironment(IResourceBuilder<T>, string, EndpointReference)Section titled WithEnvironment(IResourceBuilder<T>, string, EndpointReference)extensionIResourceBuilder<T>endpointReference. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, EndpointReference endpointReference) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the environment variable.endpointReferenceEndpointReferenceThe endpoint from which to extract the url.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ExternalServiceResource>)Section titled WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ExternalServiceResource>)extensionIResourceBuilder<T>ExternalServiceResource. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, IResourceBuilder<ExternalServiceResource> externalService) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the environment variable.externalServiceIResourceBuilder<ExternalServiceResource>The external service.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ParameterResource>)Section titled WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<T>parameter. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, IResourceBuilder<ParameterResource> parameter) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringName of environment variable.parameterIResourceBuilder<ParameterResource>Resource builder for the parameter resource.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<IResourceWithConnectionString>)Section titled WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<IResourceWithConnectionString>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string envVarName, IResourceBuilder<IResourceWithConnectionString> resource) { // ... }}Parameters
builderIResourceBuilder<T>The destination resource builder to which the environment variable will be added.envVarNamestringThe name of the environment variable under which the connection string will be set.resourceIResourceBuilder<IResourceWithConnectionString>The resource builder of the referenced service from which to pull the connection string.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithEnvironment(IResourceBuilder<T>, string, IExpressionValue)Section titled WithEnvironment(IResourceBuilder<T>, string, IExpressionValue)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, IExpressionValue value) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the environment variable.valueIExpressionValueThe value that provides both runtime values and manifest expressions.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
withEnvironment overload instead.WithEnvironment(IResourceBuilder<T>, string, TValue)Section titled WithEnvironment(IResourceBuilder<T>, string, TValue)extensionIResourceBuilder<T>IValueProvider and IManifestExpressionProvider. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T, TValue>( this IResourceBuilder<T> builder, string name, TValue value) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.namestringThe name of the environment variable.valueTValueThe value that provides both runtime values and manifest expressions.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
WithExplicitStart(IResourceBuilder<T>)Section titled WithExplicitStart(IResourceBuilder<T>)extensionIResourceBuilder<T>ExplicitStartupAnnotation annotation to the resource so it doesn't automatically start with the app host startup. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithExplicitStart<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method is useful when a resource shouldn't automatically start when the app host starts.
The database clean up tool project isn't started with the app host. The resource start command can be used to run it ondemand later.var builder = DistributedApplication.CreateBuilder(args);var pgsql = builder.AddPostgres("postgres");builder.AddProject<Projects.CleanUpDatabase>("dbcleanuptool") .WithReference(pgsql) .WithExplicitStart();WithExternalHttpEndpoints(IResourceBuilder<T>)Section titled WithExternalHttpEndpoints(IResourceBuilder<T>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithExternalHttpEndpoints<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.WithHealthCheck(IResourceBuilder<T>, string)Section titled WithHealthCheck(IResourceBuilder<T>, string)extensionIResourceBuilder<T>HealthCheckAnnotation to the resource annotations to associate a resource with a named health check managed by the health check service. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHealthCheck<T>( this IResourceBuilder<T> builder, string key) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.keystringThe key for the health check.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
The ResourceBuilderExtensions.WithHealthCheck method is used in conjunction with the ResourceBuilderExtensions.WaitFor to associate a resource registered in the application hosts dependency injection container. The ResourceBuilderExtensions.WithHealthCheck method does not inject the health check itself it is purely an association mechanism.
var builder = DistributedApplication.CreateBuilder(args);
var startAfter = DateTime.Now.AddSeconds(30);
builder.Services.AddHealthChecks().AddCheck(mycheck", () =>{ return DateTime.Now > startAfter ? HealthCheckResult.Healthy( ) : HealthCheckResult.Unhealthy();});
var pg = builder.AddPostgres("pg") .WithHealthCheck("mycheck");
builder.AddProject<Projects.MyApp>("myapp") .WithReference(pg) .WaitFor( pg); // This will result in waiting for the building check, and the // custom check defined in the code.WithHttpCommand(IResourceBuilder<TResource>, string, string, string?, string?, HttpCommandOptions?)Section titled WithHttpCommand(IResourceBuilder<TResource>, string, string, string?, string?, HttpCommandOptions?)extensionIResourceBuilder<TResource>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpCommand<TResource>( this IResourceBuilder<TResource> builder, string path, string displayName, string? endpointName = null, string? commandName = null, HttpCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.pathstringThe path to send the request to when the command is invoked.displayNamestringThe display name visible in UI.endpointNamestring?optionalThe name of the HTTP endpoint on this resource to send the request to when the command is invoked.commandNamestring?optionalOptional name of the command. The name uniquely identifies the command. If a name isn't specified then it's inferred using the command's endpoint and HTTP method.commandOptionsHttpCommandOptions?optionalOptional configuration for the command.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
The command will be added to the resource represented by builder.
If endpointName is specified, the request will be sent to the endpoint with that name on the resource represented by builder. If an endpoint with that name is not found, or the endpoint with that name is not an HTTP endpoint, an exception will be thrown.
If no endpointName is specified, the first HTTP endpoint found on the resource will be used. HTTP endpoints with an https scheme are preferred over those with an http scheme. If no HTTP endpoint is found on the resource, an exception will be thrown.
The command will not be enabled until the endpoint is allocated and the resource the endpoint is associated with is healthy.
If HttpCommandOptions.Method is not specified, POST will be used.
Specifying HttpCommandOptions.HttpClientName will use that named Http.HttpClient when sending the request. This allows you to configure the Http.HttpClient instance with a specific handler or other options using HttpClientFactoryServiceCollectionExtensions.AddHttpClient. If HttpCommandOptions.HttpClientName is not specified, the default Http.HttpClient will be used.
The HttpCommandOptions.PrepareRequest callback will be invoked to configure the request before it is sent. This can be used to add headers or a request payload before the request is sent.
The HttpCommandOptions.GetCommandResult callback will be invoked after the response is received to determine the result of the command invocation. If this callback is not specified, the command will be considered successful if the response status code is in the 2xx range. Set HttpCommandOptions.ResultMode to flow the HTTP response body back to the command caller.
/clear-cache. var apiService = builder.AddProject>MyApiService>("api") .WithHttpCommand("/clear-cache", "Clear cache");/reset-db on endpoint named admin. The request's headers are configured to include an X-Admin-Key header for verification. var adminKey = builder.AddParameter("admin-key");var apiService = builder.AddProject>MyApiService>("api") .WithHttpsEndpoint("admin") .WithEnvironment("ADMIN_KEY", adminKey) .WithHttpCommand("/reset-db", "Reset database", endpointName: "admin", commandOptions: new () { Method = HttpMethod.Get, ConfirmationMessage = "Are you sure you want to reset the database?", PrepareRequest: request => { request.Headers.Add("X-Admin-Key", adminKey); return Task.CompletedTask; } });This method is not available in polyglot app hosts.
WithHttpCommand(IResourceBuilder<TResource>, string, string, Func<EndpointReference>, string?, HttpCommandOptions?)Section titled WithHttpCommand(IResourceBuilder<TResource>, string, string, Func<EndpointReference>, string?, HttpCommandOptions?)extensionIResourceBuilder<TResource>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpCommand<TResource>( this IResourceBuilder<TResource> builder, string path, string displayName, Func<EndpointReference>? endpointSelector, string? commandName = null, HttpCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.pathstringThe path to send the request to when the command is invoked.displayNamestringThe display name visible in UI.endpointSelectorFunc<EndpointReference>A callback that selects the HTTP endpoint to send the request to when the command is invoked.commandNamestring?optionalThe name of command. The name uniquely identifies the command.commandOptionsHttpCommandOptions?optionalOptional configuration for the command.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Exceptions
Remarks
The command will be added to the resource represented by builder.
If no HttpCommandOptions.EndpointSelector is specified, the first HTTP endpoint found on the resource will be used. HTTP endpoints with an https scheme are preferred over those with an http scheme. If no HTTP endpoint is found on the resource, an exception will be thrown.
The supplied HttpCommandOptions.EndpointSelector may return an endpoint from a different resource to that which the command is being added to.
The command will not be enabled until the endpoint is allocated and the resource the endpoint is associated with is healthy.
If HttpCommandOptions.Method is not specified, POST will be used.
Specifying a HttpCommandOptions.HttpClientName will use that named Http.HttpClient when sending the request. This allows you to configure the Http.HttpClient instance with a specific handler or other options using HttpClientFactoryServiceCollectionExtensions.AddHttpClient. If no HttpCommandOptions.HttpClientName is specified, the default Http.HttpClient will be used.
The HttpCommandOptions.PrepareRequest callback will be invoked to configure the request before it is sent. This can be used to add headers or a request payload before the request is sent.
The HttpCommandOptions.GetCommandResult callback will be invoked after the response is received to determine the result of the command invocation. If this callback is not specified, the command will be considered successful if the response status code is in the 2xx range. Set HttpCommandOptions.ResultMode to flow the HTTP response body back to the command caller.
var loadGenerator = builder.AddProject>LoadGenerator>("load");var loadGeneratorEndpoint = loadGenerator.GetEndpoint("https");var customerService = builder.AddProject>CustomerService>("customer-service") .WithHttpCommand( "/stress?resource=customer-service&requests=1000", "Apply load (1000)", endpointSelector: () => loadGeneratorEndpoint) .WithHttpCommand( "/stress?resource=customer-service&requests=5000", "Apply load (5000)", endpointSelector: () => loadGeneratorEndpoint);loadGenerator.WithReference(customerService);This method is not available in polyglot app hosts.
WithHttpEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool?)Section titled WithHttpEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool?)extensionIResourceBuilder<T>ResourceBuilderExtensions.GetEndpoint. The endpoint name will be "http" if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpEndpoint<T>( this IResourceBuilder<T> builder, int? port = null, int? targetPort = null, string? name = null, string? env = null, bool? isProxied = null) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.portint?optionalAn optional port. This is the port that will be given to other resource to communicate with this resource.targetPortint?optionalThis is the port the resource is listening on. If the endpoint is used for the container, it is the container port.namestring?optionalAn optional name of the endpoint. Defaults to "http" if not specified.envstring?optionalAn optional name of the environment variable to inject.isProxiedbool?optionalSpecifies if the endpoint will be proxied by DCP. Defaults to null.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
null will not modify the existing endpoint's values. WithHttpEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool)Section titled WithHttpEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? name, string? env, bool isProxied) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.portint?An optional port. This is the port that will be given to other resource to communicate with this resource.targetPortint?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.namestring?An optional name of the endpoint. Defaults to "http" if not specified.envstring?An optional name of the environment variable to inject.isProxiedboolSpecifies if the endpoint will be proxied by DCP.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
bool isProxied signature. New source that omits isProxied binds to the nullable overload where omission is represented as null. WithHttpHealthCheck(IResourceBuilder<T>, string?, int?, string?)Section titled WithHttpHealthCheck(IResourceBuilder<T>, string?, int?, string?)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpHealthCheck<T>( this IResourceBuilder<T> builder, string? path = null, int? statusCode = null, string? endpointName = null) { // ... }}Parameters
builderIResourceBuilder<T>A resource builder.pathstring?optionalThe relative path to test.statusCodeint?optionalThe result code to interpret as healthy.endpointNamestring?optionalThe name of the endpoint to derive the base address from.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method adds a health check to the health check service which polls the specified endpoint on the resource on a periodic basis. The base address is dynamically determined based on the endpoint that was selected. By default the path is set to "/" and the status code is set to 200.
This example shows adding an HTTP health check to a backend project. The health check makes sure that the front end does not start until the backend is reporting a healthy status based on the return code returned from the "/health" path on the backend server.var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend") .WithHttpHealthCheck("/health");builder.AddProject<Projects.Frontend>("frontend") .WithReference(backend).WaitFor(backend);WithHttpHealthCheck(IResourceBuilder<T>, Func<EndpointReference>, string?, int?)Section titled WithHttpHealthCheck(IResourceBuilder<T>, Func<EndpointReference>, string?, int?)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpHealthCheck<T>( this IResourceBuilder<T> builder, Func<EndpointReference>? endpointSelector, string? path = null, int? statusCode = null) { // ... }}Parameters
builderIResourceBuilder<T>A resource builder.endpointSelectorFunc<EndpointReference>pathstring?optionalThe relative path to test.statusCodeint?optionalThe result code to interpret as healthy.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method adds a health check to the health check service which polls the specified endpoint on a periodic basis. The base address is dynamically determined based on the endpoint that was selected. By default the path is set to "/" and the status code is set to 200.
This example shows adding an HTTP health check to a backend project. The health check makes sure that the front end does not start until the backend is reporting a healthy status based on the return code returned from the "/health" path on the backend server.var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend");backend.WithHttpHealthCheck(() => backend.GetEndpoint("https"), path: "/health")builder.AddProject<Projects.Frontend>("frontend") .WithReference(backend).WaitFor(backend);This method is not available in polyglot app hosts. Use the endpointName-based overload instead.
WithHttpProbe(IResourceBuilder<T>, ProbeType, string?, int?, int?, int?, int?, int?, string?)Section titled WithHttpProbe(IResourceBuilder<T>, ProbeType, string?, int?, int?, int?, int?, int?, string?)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpProbe<T>( this IResourceBuilder<T> builder, ProbeType type, string? path = null, int? initialDelaySeconds = null, int? periodSeconds = null, int? timeoutSeconds = null, int? failureThreshold = null, int? successThreshold = null, string? endpointName = null) { // ... }}Parameters
builderIResourceBuilder<T>Resource builder.typeProbeTypeType of the probe.pathstring?optionalThe path to be used.initialDelaySecondsint?optionalThe initial delay before calling the probe endpoint for the first time.periodSecondsint?optionalThe period between each probe.timeoutSecondsint?optionalNumber of seconds after which the probe times out.failureThresholdint?optionalNumber of failures in a row before considers that the overall check has failed.successThresholdint?optionalMinimum consecutive successes for the probe to be considered successful after having failed.endpointNamestring?optionalThe name of the endpoint to be used for the probe.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
This method allows you to specify a probe and implicit adds an http health check to the resource based on probe parameters.
For example add a probe to a resource in this way:var service = builder.AddProject<Projects.MyService>("service") .WithHttpProbe(ProbeType.Liveness, "/health");var service = builder.AddProject<Projects.MyService>("service") .WithHttpProbe(ProbeType.Liveness, "/health") .WithHttpHealthCheck("/health");This method is not available in polyglot app hosts. The parameter name 'type' is a reserved keyword in Go and Rust.
WithHttpProbe(IResourceBuilder<T>, ProbeType, Func<EndpointReference>, string?, int?, int?, int?, int?, int?)Section titled WithHttpProbe(IResourceBuilder<T>, ProbeType, Func<EndpointReference>, string?, int?, int?, int?, int?, int?)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpProbe<T>( this IResourceBuilder<T> builder, ProbeType type, Func<EndpointReference>? endpointSelector, string? path = null, int? initialDelaySeconds = null, int? periodSeconds = null, int? timeoutSeconds = null, int? failureThreshold = null, int? successThreshold = null) { // ... }}Parameters
builderIResourceBuilder<T>Resource builder.typeProbeTypeType of the probe.endpointSelectorFunc<EndpointReference>The selector used to get endpoint reference.pathstring?optionalThe path to be used.initialDelaySecondsint?optionalThe initial delay before calling the probe endpoint for the first time.periodSecondsint?optionalThe period between each probe.timeoutSecondsint?optionalNumber of seconds after which the probe times out.failureThresholdint?optionalNumber of failures in a row before considers that the overall check has failed.successThresholdint?optionalMinimum consecutive successes for the probe to be considered successful after having failed.Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
This method allows you to specify a probe and implicit adds an http health check to the resource based on probe parameters.
For example add a probe to a resource in this way:var service = builder.AddProject<Projects.MyService>("service") .WithHttpProbe(ProbeType.Liveness, "/health");var service = builder.AddProject<Projects.MyService>("service") .WithHttpProbe(ProbeType.Liveness, "/health") .WithHttpHealthCheck("/health");This method is not available in polyglot app hosts. Use the endpointName-based overload instead.
WithHttpsCertificate(IResourceBuilder<TResource>, X509Certificate2, IResourceBuilder<ParameterResource>)Section titled WithHttpsCertificate(IResourceBuilder<TResource>, X509Certificate2, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<TResource>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. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpsCertificate<TResource>( this IResourceBuilder<TResource> builder, X509Certificate2 certificate, IResourceBuilder<ParameterResource>? password = null) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.certificateX509Certificate2An X509Certificates.X509Certificate2 key pair to use for HTTPS/TLS endpoints on the resource.passwordIResourceBuilder<ParameterResource>optionalA parameter specifying the password used to encrypt the certificate private key.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
var certificate = new X509Certificate2("path/to/certificate.pfx", "password");builder.AddContainer("my-service", "my-image") .WithHttpsCertificate(certificate);This method is not available in polyglot app hosts. Use ResourceBuilderExtensions.WithHttpsDeveloperCertificate instead.
WithHttpsCertificateConfiguration(IResourceBuilder<TResource>, Func<HttpsCertificateConfigurationCallbackAnnotationContext, Task>)Section titled WithHttpsCertificateConfiguration(IResourceBuilder<TResource>, Func<HttpsCertificateConfigurationCallbackAnnotationContext, Task>)extensionIResourceBuilder<TResource>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpsCertificateConfiguration<TResource>( this IResourceBuilder<TResource> builder, Func<HttpsCertificateConfigurationCallbackAnnotationContext, Task> callback) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.callbackFunc<HttpsCertificateConfigurationCallbackAnnotationContext, Task>The callback to configure the resource to use a certificate key pair.Returns
IResourceBuilder<TResource>The updated resource builder.Remarks
builder.AddContainer("my-service", "my-image") .WithHttpsCertificateConfiguration(ctx => { ctx.Arguments.Add("--https-certificate-path"); ctx.Arguments.Add(ctx.PfxPath); return Task.CompletedTask; });This method is not available in polyglot app hosts.
WithHttpsDeveloperCertificate(IResourceBuilder<TResource>, IResourceBuilder<ParameterResource>)Section titled WithHttpsDeveloperCertificate(IResourceBuilder<TResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<TResource>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpsDeveloperCertificate<TResource>( this IResourceBuilder<TResource> builder, IResourceBuilder<ParameterResource>? password = null) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.passwordIResourceBuilder<ParameterResource>optionalA parameter specifying the password used to encrypt the certificate private key.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
builder.AddContainer("my-service", "my-image") .WithHttpsDeveloperCertificate()WithHttpsEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool?)Section titled WithHttpsEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool?)extensionIResourceBuilder<T>ResourceBuilderExtensions.GetEndpoint. The endpoint name will be "https" if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpsEndpoint<T>( this IResourceBuilder<T> builder, int? port = null, int? targetPort = null, string? name = null, string? env = null, bool? isProxied = null) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.portint?optionalAn optional host port.targetPortint?optionalThis is the port the resource is listening on. If the endpoint is used for the container, it is the container port.namestring?optionalAn optional name of the endpoint. Defaults to "https" if not specified.envstring?optionalAn optional name of the environment variable to inject.isProxiedbool?optionalSpecifies if the endpoint will be proxied by DCP. Defaults to null.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
null will not modify the existing endpoint's values. WithHttpsEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool)Section titled WithHttpsEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpsEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? name, string? env, bool isProxied) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.portint?An optional host port.targetPortint?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.namestring?An optional name of the endpoint. Defaults to "https" if not specified.envstring?An optional name of the environment variable to inject.isProxiedboolSpecifies if the endpoint will be proxied by DCP.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
bool isProxied signature. New source that omits isProxied binds to the nullable overload where omission is represented as null. WithHttpsHealthCheck(IResourceBuilder<T>, string?, int?, string?)Section titled WithHttpsHealthCheck(IResourceBuilder<T>, string?, int?, string?)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpsHealthCheck<T>( this IResourceBuilder<T> builder, string? path = null, int? statusCode = null, string? endpointName = null) { // ... }}Parameters
builderIResourceBuilder<T>A resource builder.pathstring?optionalThe relative path to test.statusCodeint?optionalThe result code to interpret as healthy.endpointNamestring?optionalThe name of the endpoint to derive the base address from.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method adds a health check to the health check service which polls the specified endpoint on the resource on a periodic basis. The base address is dynamically determined based on the endpoint that was selected. By default the path is set to "/" and the status code is set to 200.
This example shows adding an HTTPS health check to a backend project. The health check makes sure that the front end does not start until the backend is reporting a healthy status based on the return code returned from the "/health" path on the backend server.var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend") .WithHttpsHealthCheck("/health");builder.AddProject<Projects.Frontend>("frontend") .WithReference(backend).WaitFor(backend);WithIconName(IResourceBuilder<T>, string, IconVariant)Section titled WithIconName(IResourceBuilder<T>, string, IconVariant)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithIconName<T>( this IResourceBuilder<T> builder, string iconName, IconVariant iconVariant = IconVariant.Filled) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.iconNamestringThe name of the FluentUI icon to use. See https://aka.ms/fluentui-system-icons for available icons.iconVariantIconVariantoptionalThe variant of the icon (Regular or Filled). Defaults to Filled.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method allows you to specify a custom FluentUI icon that will be displayed for the resource in the dashboard. If no custom icon is specified, the dashboard will use default icons based on the resource type.
Set a Redis resource to use the Database icon:var redis = builder.AddContainer("redis", "redis:latest") .WithIconName("Database");var service = builder.AddProject<Projects.MyService>("service") .WithIconName("CloudArrowUp", IconVariant.Regular);WithImagePushOptions(IResourceBuilder<T>, Action<ContainerImagePushOptionsCallbackContext>)Section titled WithImagePushOptions(IResourceBuilder<T>, Action<ContainerImagePushOptionsCallbackContext>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithImagePushOptions<T>( this IResourceBuilder<T> builder, Action<ContainerImagePushOptionsCallbackContext> callback) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.callbackAction<ContainerImagePushOptionsCallbackContext>The callback to configure push options.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
ArgumentNullExceptionThrown when builder or callback is null.Remarks
ContainerImagePushOptionsCallbackContext that provides access to the resource and the ContainerImagePushOptions that can be modified. Multiple callbacks can be registered on the same resource, and they will be invoked in the order they were added. Examples
Configure a custom image name and tag for a container resource:
var container = builder.AddContainer("myapp", "myapp:latest") .WithImagePushOptions(context => { context.Options.RemoteImageName = "myorg/myapp"; context.Options.RemoteImageTag = "v1.0.0"; });WithImagePushOptions(IResourceBuilder<T>, Func<ContainerImagePushOptionsCallbackContext, Task>)Section titled WithImagePushOptions(IResourceBuilder<T>, Func<ContainerImagePushOptionsCallbackContext, Task>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithImagePushOptions<T>( this IResourceBuilder<T> builder, Func<ContainerImagePushOptionsCallbackContext, Task> callback) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.callbackFunc<ContainerImagePushOptionsCallbackContext, Task>The asynchronous callback to configure push options.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
ArgumentNullExceptionThrown when builder or callback is null.Remarks
ContainerImagePushOptionsCallbackContext that provides access to the resource and the ContainerImagePushOptions that can be modified. Multiple callbacks can be registered on the same resource, and they will be invoked in the order they were added. Examples
Configure image options asynchronously by retrieving values from configuration:
var container = builder.AddContainer("myapp", "myapp:latest") .WithImagePushOptions(async context => { var config = await GetConfigurationAsync(); context.Options.RemoteImageName = config.ImageName; context.Options.RemoteImageTag = config.ImageTag; });WithLifetimeOf(IResourceBuilder<T>, IResourceBuilder<TSource>)Section titled WithLifetimeOf(IResourceBuilder<T>, IResourceBuilder<TSource>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithLifetimeOf<T, TSource>( this IResourceBuilder<T> builder, IResourceBuilder<TSource> sourceBuilder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.sourceBuilderIResourceBuilder<TSource>The resource builder whose lifetime should be used.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
InvalidOperationExceptionThrown when the resource does not support lifetime configuration.Remarks
sourceBuilder when the application model is prepared, so later lifetime changes to the source resource are reflected by this resource. WithManifestPublishingCallback(IResourceBuilder<T>, Action<ManifestPublishingContext>)Section titled WithManifestPublishingCallback(IResourceBuilder<T>, Action<ManifestPublishingContext>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithManifestPublishingCallback<T>( this IResourceBuilder<T> builder, Action<ManifestPublishingContext> callback) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.callbackAction<ManifestPublishingContext>Callback method which takes a ManifestPublishingContext which can be used to inject JSON into the manifest.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
WithManifestPublishingCallback(IResourceBuilder<T>, Func<ManifestPublishingContext, Task>)Section titled WithManifestPublishingCallback(IResourceBuilder<T>, Func<ManifestPublishingContext, Task>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithManifestPublishingCallback<T>( this IResourceBuilder<T> builder, Func<ManifestPublishingContext, Task> callback) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.callbackFunc<ManifestPublishingContext, Task>Callback method which takes a ManifestPublishingContext which can be used to inject JSON into the manifest.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
WithoutHttpsCertificate(IResourceBuilder<TResource>)Section titled WithoutHttpsCertificate(IResourceBuilder<TResource>)extensionIResourceBuilder<TResource>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithoutHttpsCertificate<TResource>( this IResourceBuilder<TResource> builder) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
var redis = builder.AddRedis("cache") .WithoutHttpsCertificate();WithParentProcessLifetime(IResourceBuilder<T>, int)Section titled WithParentProcessLifetime(IResourceBuilder<T>, int)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithParentProcessLifetime<T>( this IResourceBuilder<T> builder, int parentProcessId) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.parentProcessIdintThe ID of the parent process to monitor.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
ArgumentOutOfRangeExceptionThrown when parentProcessId is less than or equal to zero.ArgumentExceptionThrown when parentProcessId does not identify a running process.InvalidOperationExceptionThrown when the resource does not support lifetime configuration.Remarks
var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<Projects.ApiService>("api") .WithParentProcessLifetime(parentProcessId: 1234);
builder.Build().Run();WithParentRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)Section titled WithParentRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIResourceBuilder<T>ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithParentRelationship<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> parent) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.parentIResourceBuilder<IResource>The parent of builder.Returns
IResourceBuilder<T>A resource builder.Remarks
The WithParentRelationship method is used to add parent relationships to the resource. Relationships are used to link resources together in UI.
var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend");
var frontend = builder.AddProject<Projects.Manager>("frontend") .WithParentRelationship(backend);WithParentRelationship(IResourceBuilder<T>, IResource)Section titled WithParentRelationship(IResourceBuilder<T>, IResource)extensionIResourceBuilder<T>ResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithParentRelationship<T>( this IResourceBuilder<T> builder, IResource parent) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.parentIResourceThe parent of builder.Returns
IResourceBuilder<T>A resource builder.Remarks
The WithParentRelationship method is used to add parent relationships to the resource. Relationships are used to link resources together in UI.
var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend");
var frontend = builder.AddProject<Projects.Manager>("frontend") .WithParentRelationship(backend.Resource);This method is not available in polyglot app hosts. Use the IResourceBuilder overload instead.
WithPersistentLifetime(IResourceBuilder<T>)Section titled WithPersistentLifetime(IResourceBuilder<T>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithPersistentLifetime<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
InvalidOperationExceptionThrown when the resource does not support lifetime configuration.Remarks
var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<Projects.ApiService>("api") .WithPersistentLifetime();
builder.Build().Run();WithProcessCommand(IResourceBuilder<TResource>, string, string, string, IReadOnlyList<string>, ProcessCommandOptions?)Section titled WithProcessCommand(IResourceBuilder<TResource>, string, string, string, IReadOnlyList<string>, ProcessCommandOptions?)extensionIResourceBuilder<TResource>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithProcessCommand<TResource>( this IResourceBuilder<TResource> builder, string commandName, string displayName, string executablePath, IReadOnlyList<string>? arguments = null, ProcessCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.commandNamestringThe name of command. The name uniquely identifies the command.displayNamestringThe display name visible in UI.executablePathstringThe executable path or command name to start.argumentsIReadOnlyList<string>optionalThe command-line arguments for the process.commandOptionsProcessCommandOptions?optionalOptional configuration for the command.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
The command will be added to the resource represented by builder. When the command executes, the process is started inside the AppHost process. Standard output and standard error are streamed to the command logger and a bounded tail of the combined output is returned as command result data.
This C# overload is not exported to polyglot app hosts. Use the language-specific static process command API instead.
Examples
var redis = builder.AddRedis("cache") .WithProcessCommand("dotnet-version", "Show .NET version", "dotnet", ["--version"]);WithProcessCommand(IResourceBuilder<TResource>, string, string, Func<ExecuteCommandContext, ProcessCommandSpec>, ProcessCommandOptions?)Section titled WithProcessCommand(IResourceBuilder<TResource>, string, string, Func<ExecuteCommandContext, ProcessCommandSpec>, ProcessCommandOptions?)extensionIResourceBuilder<TResource>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithProcessCommand<TResource>( this IResourceBuilder<TResource> builder, string commandName, string displayName, Func<ExecuteCommandContext, ProcessCommandSpec> processSpecFactory, ProcessCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.commandNamestringThe name of command. The name uniquely identifies the command.displayNamestringThe display name visible in UI.processSpecFactoryFunc<ExecuteCommandContext, ProcessCommandSpec>A callback that creates the local process specification when the command is invoked.commandOptionsProcessCommandOptions?optionalOptional configuration for the command.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
The command will be added to the resource represented by builder. When the command executes, processSpecFactory is called inside the AppHost process with the command execution context. Use ExecuteCommandContext.Arguments to read values supplied by the command caller.
Standard output and standard error are streamed to the command logger at LogLevel.Debug and a bounded tail of the combined output is returned as command result data. Configure ProcessCommandOptions.SuccessExitCodes to control which exit codes are treated as success. Configure ProcessCommandOptions.MaxOutputLineCount to control the number of returned output lines. Configure ProcessCommandOptions.DisplayImmediately to control whether returned output opens automatically in the dashboard. Configure ProcessCommandOptions.GetCommandResult to create a custom command result from the process exit code and output.
This C# callback overload is not available in polyglot app hosts.
Examples
var redis = builder.AddRedis("cache") .WithProcessCommand( "seed-data", "Seed data", context => new ProcessCommandSpec("dotnet") { Arguments = ["run", "--project", "tools/SeedData", "--", context.Arguments.GetString("dataset") ?? "small"], EnvironmentVariables = { ["ConnectionStrings__db"] = "Host=localhost;Database=db" } }, new ProcessCommandOptions { MaxOutputLineCount = 20 });WithProcessCommand(IResourceBuilder<TResource>, string, string, Func<ExecuteCommandContext, ValueTask<ProcessCommandSpec>>, ProcessCommandOptions?)Section titled WithProcessCommand(IResourceBuilder<TResource>, string, string, Func<ExecuteCommandContext, ValueTask<ProcessCommandSpec>>, ProcessCommandOptions?)extensionIResourceBuilder<TResource>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithProcessCommand<TResource>( this IResourceBuilder<TResource> builder, string commandName, string displayName, Func<ExecuteCommandContext, ValueTask<ProcessCommandSpec>> processSpecFactory, ProcessCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource>The resource builder.commandNamestringThe name of command. The name uniquely identifies the command.displayNamestringThe display name visible in UI.processSpecFactoryFunc<ExecuteCommandContext, ValueTask<ProcessCommandSpec>>A callback that creates the local process specification when the command is invoked.commandOptionsProcessCommandOptions?optionalOptional configuration for the command.Returns
IResourceBuilder<TResource>The ApplicationModel.IResourceBuilder`1.Remarks
The command will be added to the resource represented by builder. When the command executes, processSpecFactory is called inside the AppHost process with the command execution context. Use ExecuteCommandContext.Arguments to read values supplied by the command caller.
Standard output and standard error are streamed to the command logger at LogLevel.Debug and a bounded tail of the combined output is returned as command result data. Configure ProcessCommandOptions.SuccessExitCodes to control which exit codes are treated as success. Configure ProcessCommandOptions.MaxOutputLineCount to control the number of returned output lines. Configure ProcessCommandOptions.DisplayImmediately to control whether returned output opens automatically in the dashboard. Configure ProcessCommandOptions.GetCommandResult to create a custom command result from the process exit code and output.
This C# callback overload is not available in polyglot app hosts.
Examples
var redis = builder.AddRedis("cache") .WithProcessCommand( "seed-data", "Seed data", context => new ValueTask<ProcessCommandSpec>(new ProcessCommandSpec("dotnet") { Arguments = ["run", "--project", "tools/SeedData", "--", context.Arguments.GetString("dataset") ?? "small"], StandardInputContent = "seed" }));WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, string?, bool)Section titled WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, string?, bool)extensionIResourceBuilder<TDestination> 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.
public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, IResourceBuilder<IResourceWithConnectionString> source, string? connectionName = null, bool optional = false) { // ... }}Parameters
builderIResourceBuilder<TDestination>The resource where connection string will be injected.sourceIResourceBuilder<IResourceWithConnectionString>The resource from which to extract the connection string.connectionNamestring?optionalAn override of the source resource's name for the connection string. The resulting connection string will be "ConnectionStrings__connectionName" if this is not null.optionalbooloptionaltrue to allow a missing connection string; false to throw an exception if the connection string is not found.Returns
IResourceBuilder<TDestination>The ApplicationModel.IResourceBuilder`1.Exceptions
DistributedApplicationExceptionThrows 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.WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>)Section titled WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>)extensionIResourceBuilder<TDestination>EndpointAnnotation.ExcludeReferenceEndpoint is false) defined on the source 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. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, IResourceBuilder<IResourceWithServiceDiscovery> source) { // ... }}Parameters
builderIResourceBuilder<TDestination>The resource where the service discovery information will be injected.sourceIResourceBuilder<IResourceWithServiceDiscovery>The resource from which to extract service discovery information.Returns
IResourceBuilder<TDestination>The ApplicationModel.IResourceBuilder`1.Remarks
All endpoints are included in the default reference set unless explicitly excluded. Resource authors can opt out individual endpoints by setting EndpointAnnotation.ExcludeReferenceEndpoint to true (for example, using .WithEndpoint("endpointName", e => e.ExcludeReferenceEndpoint = true)) to exclude them from this method's behavior. Endpoints that have been excluded (such as management or health check endpoints) can still be referenced explicitly using ResourceBuilderExtensions.WithReference with ResourceBuilderExtensions.GetEndpoint.
WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>, string)Section titled WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>, string)extensionIResourceBuilder<TDestination>EndpointAnnotation.ExcludeReferenceEndpoint is false) defined on the source 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. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, IResourceBuilder<IResourceWithServiceDiscovery> source, string name) { // ... }}Parameters
builderIResourceBuilder<TDestination>The resource where the service discovery information will be injected.sourceIResourceBuilder<IResourceWithServiceDiscovery>The resource from which to extract service discovery information.namestringThe name of the resource for the environment variable.Returns
IResourceBuilder<TDestination>The ApplicationModel.IResourceBuilder`1.Remarks
All endpoints are included in the default reference set unless explicitly excluded. Resource authors can opt out individual endpoints by setting EndpointAnnotation.ExcludeReferenceEndpoint to true (for example, using .WithEndpoint("endpointName", e => e.ExcludeReferenceEndpoint = true)) to exclude them from this method's behavior. Endpoints that have been excluded (such as management or health check endpoints) can still be referenced explicitly using ResourceBuilderExtensions.WithReference with ResourceBuilderExtensions.GetEndpoint.
WithReference(IResourceBuilder<TDestination>, string, Uri)Section titled WithReference(IResourceBuilder<TDestination>, string, Uri)extensionIResourceBuilder<TDestination>ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{name}__default__0={uri}" for .NET service discovery, or "{name}={uri}" for endpoint injection. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, string name, Uri uri) { // ... }}Parameters
builderIResourceBuilder<TDestination>The resource where the service discovery information will be injected.namestringThe name of the service.uriUriThe uri of the service.Returns
IResourceBuilder<TDestination>The ApplicationModel.IResourceBuilder`1.WithReference(IResourceBuilder<TDestination>, IResourceBuilder<ExternalServiceResource>)Section titled WithReference(IResourceBuilder<TDestination>, IResourceBuilder<ExternalServiceResource>)extensionIResourceBuilder<TDestination>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}." public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, IResourceBuilder<ExternalServiceResource> externalService) { // ... }}Parameters
builderIResourceBuilder<TDestination>The resource where the service discovery information will be injected.externalServiceIResourceBuilder<ExternalServiceResource>The external service.Returns
IResourceBuilder<TDestination>The ApplicationModel.IResourceBuilder`1.WithReference(IResourceBuilder<TDestination>, EndpointReference)Section titled WithReference(IResourceBuilder<TDestination>, EndpointReference)extensionIResourceBuilder<TDestination>ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{name}__{endpointScheme}__{endpointIndex}={uriString}" for .NET service discovery, or "{NAME}_{ENDPOINT}={uri}" for endpoint injection. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, EndpointReference endpointReference) { // ... }}Parameters
builderIResourceBuilder<TDestination>The resource where the service discovery information will be injected.endpointReferenceEndpointReferenceThe endpoint from which to extract the url.Returns
IResourceBuilder<TDestination>The ApplicationModel.IResourceBuilder`1.WithReferenceEnvironment(IResourceBuilder<TDestination>, ReferenceEnvironmentInjectionFlags)Section titled WithReferenceEnvironment(IResourceBuilder<TDestination>, ReferenceEnvironmentInjectionFlags)extensionIResourceBuilder<TDestination>public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReferenceEnvironment<TDestination>( this IResourceBuilder<TDestination> builder, ReferenceEnvironmentInjectionFlags flags) { // ... }}Parameters
builderIResourceBuilder<TDestination>The resource to configure.flagsReferenceEnvironmentInjectionFlagsThe injection flags determining which reference information is emitted.Returns
IResourceBuilder<TDestination>The ApplicationModel.IResourceBuilder`1.Remarks
WithReferenceRelationship(IResourceBuilder<T>, IResource)Section titled WithReferenceRelationship(IResourceBuilder<T>, IResource)extensionIResourceBuilder<T>ResourceRelationshipAnnotation to the resource annotations to add a reference to another resource. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithReferenceRelationship<T>( this IResourceBuilder<T> builder, IResource resource) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.resourceIResourceThe resource that the relationship is to.Returns
IResourceBuilder<T>A resource builder.Remarks
WithReferenceRelationship(IResourceBuilder<T>, ReferenceExpression)Section titled WithReferenceRelationship(IResourceBuilder<T>, ReferenceExpression)extensionIResourceBuilder<T>ResourceRelationshipAnnotation s for all resources found in the expression. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithReferenceRelationship<T>( this IResourceBuilder<T> builder, ReferenceExpression expression) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.expressionReferenceExpressionThe reference expression.Returns
IResourceBuilder<T>A resource builder.Remarks
WithReferenceRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)Section titled WithReferenceRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIResourceBuilder<T>ResourceRelationshipAnnotation to the resource annotations to add a reference to another resource. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithReferenceRelationship<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> resourceBuilder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.resourceBuilderIResourceBuilder<IResource>The resource builder that the relationship is to.Returns
IResourceBuilder<T>A resource builder.Remarks
WithRelationship(IResourceBuilder<T>, IResource, string)Section titled WithRelationship(IResourceBuilder<T>, IResource, string)extensionIResourceBuilder<T>ResourceRelationshipAnnotation to the resource annotations to add a relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithRelationship<T>( this IResourceBuilder<T> builder, IResource resource, string type) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.resourceIResourceThe resource that the relationship is to.typestringThe relationship type.Returns
IResourceBuilder<T>A resource builder.Remarks
The WithRelationship method is used to add relationships to the resource. Relationships are used to link resources together in UI. The type indicates information about the relationship type.
var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend");var manager = builder.AddProject<Projects.Manager>("manager") .WithRelationship(backend.Resource, "Manager");This method is not available in polyglot app hosts.
WithRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>, string)Section titled WithRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>, string)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithRelationship<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> resourceBuilder, string type) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.resourceBuilderIResourceBuilder<IResource>The resource builder that the relationship is to.typestringThe relationship type.Returns
IResourceBuilder<T>A resource builder.WithRemoteImageName(IResourceBuilder<T>, string)Section titled WithRemoteImageName(IResourceBuilder<T>, string)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithRemoteImageName<T>( this IResourceBuilder<T> builder, string remoteImageName) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.remoteImageNamestringThe remote image name (e.g., "myapp" or "myorg/myapp").Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
ArgumentNullExceptionThrown when builder or remoteImageName is null.Remarks
ContainerImagePushOptions.RemoteImageName property. The remote image name should not include the registry endpoint or tag. Those are managed separately. This method can be combined with ResourceBuilderExtensions.WithRemoteImageTag to fully customize the image reference. Examples
Set a custom remote image name for a container:
var container = builder.AddContainer("myapp", "myapp:latest") .WithRemoteImageName("myorg/myapp");WithRemoteImageTag(IResourceBuilder<T>, string)Section titled WithRemoteImageTag(IResourceBuilder<T>, string)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithRemoteImageTag<T>( this IResourceBuilder<T> builder, string remoteImageTag) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.remoteImageTagstringThe remote image tag (e.g., "latest", "v1.0.0").Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
ArgumentNullExceptionThrown when builder or remoteImageTag is null.Remarks
ContainerImagePushOptions.RemoteImageTag property. The tag can be any valid container image tag such as version numbers, environment names, or deployment identifiers. This method can be combined with ResourceBuilderExtensions.WithRemoteImageName to fully customize the image reference. Examples
Set a specific version tag for a container:
var container = builder.AddContainer("myapp", "myapp:latest") .WithRemoteImageTag("v1.0.0");WithSessionLifetime(IResourceBuilder<T>)Section titled WithSessionLifetime(IResourceBuilder<T>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithSessionLifetime<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIResourceBuilder<T>The resource builder.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Exceptions
InvalidOperationExceptionThrown when the resource does not support lifetime configuration.Remarks
var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<Projects.ApiService>("api") .WithSessionLifetime();
builder.Build().Run();WithUrl(IResourceBuilder<T>, string, string?)Section titled WithUrl(IResourceBuilder<T>, string, string?)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrl<T>( this IResourceBuilder<T> builder, string url, string? displayText = null) { // ... }}Parameters
builderIResourceBuilder<T>The builder for the resource.urlstringA URL to show for the resource.displayTextstring?optionalThe display text to show when the link is displayed.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
ResourceBuilderExtensions.WithUrlForEndpoint. Examples
Add a static URL to be displayed for the resource:
var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrl("https://example.com/", "Home");Update all displayed URLs to use the specified path and (optional) display text:
var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrl("/home", "Home");WithUrl(IResourceBuilder<T>, ExpressionInterpolatedStringHandler, string?)Section titled WithUrl(IResourceBuilder<T>, ExpressionInterpolatedStringHandler, string?)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrl<T>( this IResourceBuilder<T> builder, in ExpressionInterpolatedStringHandler url, string? displayText = null) { // ... }}Parameters
builderIResourceBuilder<T>The builder for the resource.urlExpressionInterpolatedStringHandlerThe interpolated string that produces the URL.displayTextstring?optionalThe display text to show when the link is displayed.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
This method is not available in polyglot app hosts. Use the ReferenceExpression overload instead.
WithUrl(IResourceBuilder<T>, ReferenceExpression, string?)Section titled WithUrl(IResourceBuilder<T>, ReferenceExpression, string?)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrl<T>( this IResourceBuilder<T> builder, ReferenceExpression url, string? displayText = null) { // ... }}Parameters
builderIResourceBuilder<T>The builder for the resource.urlReferenceExpressionA ReferenceExpression that will produce the URL.displayTextstring?optionalThe display text to show when the link is displayed.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
WithUrlForEndpoint(IResourceBuilder<T>, string, Action<ResourceUrlAnnotation>)Section titled WithUrlForEndpoint(IResourceBuilder<T>, string, Action<ResourceUrlAnnotation>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrlForEndpoint<T>( this IResourceBuilder<T> builder, string endpointName, Action<ResourceUrlAnnotation> callback) { // ... }}Parameters
builderIResourceBuilder<T>The builder for the resource.endpointNamestringThe name of the endpoint to customize the URL for.callbackAction<ResourceUrlAnnotation>The callback that will customize the URL.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
Use this method to customize the URL that is automatically added for an endpoint on the resource. To add another URL for an endpoint, use ResourceBuilderExtensions.WithUrlForEndpoint.
The callback will be executed after endpoints have been allocated and the URL has been generated. This allows you to modify the URL or its display text.
If the URL returned by callback is relative, it will be combined with the endpoint URL to create an absolute URL.
If the endpoint with the specified name does not exist, the callback will not be executed and a warning will be logged.
Customize the URL for the "https" endpoint to use the link text "Home":var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrlForEndpoint( "https", url => url.DisplayText = "Home");var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrlForEndpoint("https", url => url.Url = "/home");WithUrlForEndpoint(IResourceBuilder<T>, string, Func<EndpointReference, ResourceUrlAnnotation>)Section titled WithUrlForEndpoint(IResourceBuilder<T>, string, Func<EndpointReference, ResourceUrlAnnotation>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrlForEndpoint<T>( this IResourceBuilder<T> builder, string endpointName, Func<EndpointReference, ResourceUrlAnnotation> callback) { // ... }}Parameters
builderIResourceBuilder<T>The builder for the resource.endpointNamestringThe name of the endpoint to add the URL for.callbackFunc<EndpointReference, ResourceUrlAnnotation>The callback that will create the URL.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.Remarks
Use this method to add another URL for an endpoint on the resource. To customize the URL that is automatically added for an endpoint, use ResourceBuilderExtensions.WithUrlForEndpoint.
The callback will be executed after endpoints have been allocated and the resource is about to start.
If the endpoint with the specified name does not exist, the callback will not be executed and a warning will be logged.
Add a URL for the "https" endpoint that deep-links to an admin page with the text "Admin":var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrlForEndpoint( "https", ep => new() { Url = "/admin", DisplayText = "Admin" });WithUrls(IResourceBuilder<T>, Action<ResourceUrlsCallbackContext>)Section titled WithUrls(IResourceBuilder<T>, Action<ResourceUrlsCallbackContext>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrls<T>( this IResourceBuilder<T> builder, Action<ResourceUrlsCallbackContext> callback) { // ... }}Parameters
builderIResourceBuilder<T>The builder for the resource.callbackAction<ResourceUrlsCallbackContext>The callback that will customize URLs for the resource.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.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.
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"; } } });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(); } } });WithUrls(IResourceBuilder<T>, Func<ResourceUrlsCallbackContext, Task>)Section titled WithUrls(IResourceBuilder<T>, Func<ResourceUrlsCallbackContext, Task>)extensionIResourceBuilder<T>public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrls<T>( this IResourceBuilder<T> builder, Func<ResourceUrlsCallbackContext, Task> callback) { // ... }}Parameters
builderIResourceBuilder<T>The builder for the resource.callbackFunc<ResourceUrlsCallbackContext, Task>The async callback that will customize URLs for the resource.Returns
IResourceBuilder<T>The ApplicationModel.IResourceBuilder`1.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.