Softalleys.Utilities.Commands
1.0.2
dotnet add package Softalleys.Utilities.Commands --version 1.0.2
NuGet\Install-Package Softalleys.Utilities.Commands -Version 1.0.2
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="Softalleys.Utilities.Commands" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Softalleys.Utilities.Commands" Version="1.0.2" />
<PackageReference Include="Softalleys.Utilities.Commands" />
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 Softalleys.Utilities.Commands --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Softalleys.Utilities.Commands, 1.0.2"
#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 Softalleys.Utilities.Commands@1.0.2
#: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=Softalleys.Utilities.Commands&version=1.0.2
#tool nuget:?package=Softalleys.Utilities.Commands&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Softalleys.Utilities.Commands
Lightweight command pipeline for .NET 8/9 with validators, processors, handlers, optional post-actions, and DI scanning. Designed to pair with Softalleys.Utilities.Events and Softalleys.Utilities.Queries.
Concepts
ICommand<TResult>
: marker for a command that yields a domain-specificTResult
discriminated union (record/class hierarchy)ICommandValidator<TCommand,TResult>
: validates the command and returns aTResult
. If the result indicates "valid" the pipeline continues; otherwise, returns failure immediatelyICommandProcessor<TCommand,TResult>
: performs business logic and persistence, returning aTResult
(usually success/failure variants)ICommandHandler<TCommand,TResult>
: orchestrates the pipeline. You can implement your own or useDefaultCommandHandler<TCommand,TResult>
ICommandPostAction<TCommand,TResult>
: optional post-processing hook (publish events, logging, audit, etc.)ICommandSingletonHandler<TCommand,TResult>
: marker to opt-in Singleton lifetime instead of default ScopedICommandMediator
: sends commands to their handlers with proper scope
Installation
Once published to NuGet:
dotnet add package Softalleys.Utilities.Commands
Dependency Injection
Register and scan assemblies that contain handlers/validators/processors/post-actions:
using Softalleys.Utilities.Commands;
builder.Services.AddSoftalleysCommands(typeof(SomeHandler).Assembly);
- Mediator is registered as Singleton
- Handlers are Scoped by default (Singleton if
ICommandSingletonHandler<,>
is implemented) - Validators, processors, and post-actions are Scoped by default
Using the Default Pipeline
Define your command and result union:
public record CreateCategoryCommand(string Name, string Description, string Icon) : ICommand<CreateCategoryResult>;
public abstract record CreateCategoryResult;
public record CreateCategoryValid : CreateCategoryResult;
public record CreateCategorySuccessResult(Category Category) : CreateCategoryResult;
public record CreateCategoryFailureResult(string Title, string Message)
: CreateCategoryResult, Softalleys.Utilities.Interfaces.IErrorResponse
{
public string Error { get; init; } = "Bad Request";
public int Status { get; init; } = 400;
public IDictionary<string, string[]> Errors { get; init; } = new Dictionary<string, string[]>();
public string? TraceId { get; init; }
}
Implement validator and processor:
public class CreateCategoryValidator : ICommandValidator<CreateCategoryCommand, CreateCategoryResult>
{
public Task<CreateCategoryResult> ValidateAsync(CreateCategoryCommand cmd, CancellationToken ct = default)
# Softalleys.Utilities.Commands
Lightweight command pipeline for .NET (net8/net9) with validators, processors, default handler, post-actions and DI scanning.
Key features
- ICommand/ICommandHandler pipeline with validation and processing stages
- DefaultCommandHandler to orchestrate validation → processing → post-actions
- DI scanning for handlers, validators, processors and post-actions
- Scoped and Singleton handler support via marker interface
Install
```
dotnet add package Softalleys.Utilities.Commands --version 1.0.0
```
Quickstart
```csharp
// Register
builder.Services.AddSoftalleysCommands(typeof(SomeHandler).Assembly);
// Define command
public record CreateUserCommand(string Email, string Password) : ICommand<CreateUserResult>;
// Send
var result = await mediator.SendAsync<CreateUserResult, CreateUserCommand>(new CreateUserCommand("a@b.com","pwd"));
```
License
MIT
Source
https://github.com/Softalleys/Softalleys.Utilities
For more details and examples, see the project README in the repository.
{
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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.
-
net8.0
-
net9.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.