Udostępnij za pośrednictwem


ResourceBuilderExtensions.WithCommand<T> Method

Definition

Adds a ResourceCommandAnnotation to the resource annotations to add a resource command.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithCommand<T> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string name, string displayName, Func<Aspire.Hosting.ApplicationModel.ExecuteCommandContext,System.Threading.Tasks.Task<Aspire.Hosting.ApplicationModel.ExecuteCommandResult>> executeCommand, Func<Aspire.Hosting.ApplicationModel.UpdateCommandStateContext,Aspire.Hosting.ApplicationModel.ResourceCommandState>? updateState = default, string? displayDescription = default, object? parameter = default, string? confirmationMessage = default, string? iconName = default, Aspire.Hosting.ApplicationModel.IconVariant? iconVariant = default, bool isHighlighted = false) where T : Aspire.Hosting.ApplicationModel.IResource;
static member WithCommand : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> * string * string * Func<Aspire.Hosting.ApplicationModel.ExecuteCommandContext, System.Threading.Tasks.Task<Aspire.Hosting.ApplicationModel.ExecuteCommandResult>> * Func<Aspire.Hosting.ApplicationModel.UpdateCommandStateContext, Aspire.Hosting.ApplicationModel.ResourceCommandState> * string * obj * string * string * Nullable<Aspire.Hosting.ApplicationModel.IconVariant> * bool -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)
<Extension()>
Public Function WithCommand(Of T As IResource) (builder As IResourceBuilder(Of T), name As String, displayName As String, executeCommand As Func(Of ExecuteCommandContext, Task(Of ExecuteCommandResult)), Optional updateState As Func(Of UpdateCommandStateContext, ResourceCommandState) = Nothing, Optional displayDescription As String = Nothing, Optional parameter As Object = Nothing, Optional confirmationMessage As String = Nothing, Optional iconName As String = Nothing, Optional iconVariant As Nullable(Of IconVariant) = Nothing, Optional isHighlighted As Boolean = false) As IResourceBuilder(Of T)

Type Parameters

T

The type of the resource.

Parameters

builder
IResourceBuilder<T>

The resource builder.

name
String

The name of command. The name uniquely identifies the command.

displayName
String

The display name visible in UI.

executeCommand
Func<ExecuteCommandContext,Task<ExecuteCommandResult>>

A callback that is executed when the command is executed. The callback is run inside the .NET Aspire host. The callback result is used to indicate success or failure in the UI.

updateState
Func<UpdateCommandStateContext,ResourceCommandState>

A 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.

displayDescription
String

Optional description of the command, to be shown in the UI. Could be used as a tooltip. May be localized.

parameter
Object

Optional parameter that configures the command in some way. Clients must return any value provided by the server when invoking the command.

confirmationMessage
String

When a confirmation message is specified, the UI will prompt with an OK/Cancel dialog and the confirmation message before starting the command.

iconName
String

The icon name for the command. The name should be a valid FluentUI icon name. https://aka.ms/fluentui-system-icons

iconVariant
Nullable<IconVariant>

The icon variant.

isHighlighted
Boolean

A flag indicating whether the command is highlighted in the UI.

Returns

The resource builder.

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 .NET Aspire host.

Applies to