RequiredCommandResourceExtensions Methods
Class Methods 2 members
Provides extension methods for adding required command annotations to resources.
WithRequiredCommand(IResourceBuilder<T>, string, string?) Section titled WithRequiredCommand(IResourceBuilder<T>, string, string?) extension IResourceBuilder<T> Declares that a resource requires a specific command/executable to be available on the local machine PATH before it can start.
public static class RequiredCommandResourceExtensions{ public static IResourceBuilder<T> WithRequiredCommand<T>( this IResourceBuilder<T> builder, string command, string? helpLink = null) { // ... }}Parameters
builder IResourceBuilder<T> The resource builder. command string The command string (file name or path) that should be validated. helpLink string? optional An optional help link URL to guide users when the command is missing. Returns
IResourceBuilder<T> The resource builder. Remarks
The command is considered valid if either: 1. It is an absolute or relative path (contains a directory separator) that points to an existing file, or 2. It is discoverable on the current process PATH (respecting PATHEXT on Windows). If the command is not found, a warning message will be logged but the resource will be allowed to attempt to start.
WithRequiredCommand(IResourceBuilder<T>, string, Func<RequiredCommandValidationContext, Task<RequiredCommandValidationResult>>, string?) Section titled WithRequiredCommand(IResourceBuilder<T>, string, Func<RequiredCommandValidationContext, Task<RequiredCommandValidationResult>>, string?) extension IResourceBuilder<T> Declares that a resource requires a specific command/executable to be available on the local machine PATH before it can start, with custom validation logic.
public static class RequiredCommandResourceExtensions{ public static IResourceBuilder<T> WithRequiredCommand<T>( this IResourceBuilder<T> builder, string command, Func<RequiredCommandValidationContext, Task<RequiredCommandValidationResult>> validationCallback, string? helpLink = null) { // ... }}Parameters
builder IResourceBuilder<T> The resource builder. command string The command string (file name or path) that should be validated. validationCallback Func<RequiredCommandValidationContext, Task<RequiredCommandValidationResult>> A callback that validates the resolved command path. Receives a RequiredCommandValidationContext and returns a RequiredCommandValidationResult. helpLink string? optional An optional help link URL to guide users when the command is missing or fails validation. Returns
IResourceBuilder<T> The resource builder. Remarks
This method is not available in polyglot app hosts. Use the overload without validation callback instead.
The command is first resolved to a full path. If found, the validation callback is invoked with the context containing the resolved path and service provider. The callback should return aRequiredCommandValidationResult indicating whether the command is valid. If the command is not found or fails validation, a warning message will be logged but the resource will be allowed to attempt to start.