Ploch.CommandLine.UseCases 1.0.51

dotnet add package Ploch.CommandLine.UseCases --version 1.0.51
                    
NuGet\Install-Package Ploch.CommandLine.UseCases -Version 1.0.51
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ploch.CommandLine.UseCases" Version="1.0.51" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ploch.CommandLine.UseCases" Version="1.0.51" />
                    
Directory.Packages.props
<PackageReference Include="Ploch.CommandLine.UseCases" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ploch.CommandLine.UseCases --version 1.0.51
                    
#r "nuget: Ploch.CommandLine.UseCases, 1.0.51"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ploch.CommandLine.UseCases@1.0.51
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ploch.CommandLine.UseCases&version=1.0.51
                    
Install as a Cake Addin
#tool nuget:?package=Ploch.CommandLine.UseCases&version=1.0.51
                    
Install as a Cake Tool

Ploch.CommandLine.UseCases

Use-case abstractions for command-line applications built with Ploch.CommandLine.Spectre. Keep the work in a use case: IUseCase<TRequest, TResponse> is the general abstraction, and IResultUseCase<TRequest, TResponse> is the variant whose response is an Ardalis.Result.

UseCaseAsyncCommand runs an IResultUseCase from a command: it turns the command settings into a request, runs the use case, reports a failed result's errors and validation errors, and maps the result to an exit code. On success it prints a completion message; override ProcessSuccessResponse to render the response value itself.

Installation

dotnet add package Ploch.CommandLine.UseCases

Example

using Ardalis.Result;
using Ploch.CommandLine.Spectre.Commands;
using Ploch.CommandLine.Spectre.Output;
using Ploch.CommandLine.UseCases;
using Spectre.Console.Cli;

public record GreetRequest(string Name);

public class GreetUseCase : IResultUseCase<GreetRequest, string>
{
    public Task<Result<string>> ExecuteAsync(GreetRequest request, CancellationToken cancellationToken = default) =>
        Task.FromResult(Result.Success($"Hello, {request.Name}!"));
}

public class GreetSettings : CommandSettings
{
    [CommandOption("-n|--name")]
    public string Name { get; set; } = "world";
}

public class GreetCommand(IOutput output,
                          GreetUseCase useCase,
                          CommandArgumentsRootProcessor settingsProcessor,
                          ICommandSettingsValidator<GreetSettings> validator,
                          IExceptionHandler exceptionHandler)
    : UseCaseAsyncCommand<GreetSettings, GreetUseCase, GreetRequest, string>(output, useCase, settingsProcessor, validator, exceptionHandler)
{
    protected override GreetRequest CreateRequest(GreetSettings settings) => new(settings.Name);
}

Register the use case in the container and the command with ConfigureCommandApp, exactly as for any other command.

Documentation

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.51 76 10/30/2026