ResultCommander 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ResultCommander --version 2.0.1
                    
NuGet\Install-Package ResultCommander -Version 2.0.1
                    
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="ResultCommander" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ResultCommander" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ResultCommander" />
                    
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 ResultCommander --version 2.0.1
                    
#r "nuget: ResultCommander, 2.0.1"
                    
#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 ResultCommander@2.0.1
                    
#: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=ResultCommander&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ResultCommander&version=2.0.1
                    
Install as a Cake Tool

ResultCommander

Build Status

Library featuring a command handler pattern for both synchronous and asynchronous operations.

Uses a functional Result approach for failure-prone operations.

To utilize all features using Autofac is required.

Features

  • Synchronous and asynchronous command handler definitions
  • Definitions and base implementations of commands
  • Supports decorators and adapters via Autofac's methods

Description

There are two command types - one that only returns a Result and one that returns an additional entity contained within the Result.

Every handler must return a Result struct which determines whether the operation succedeed or not, handlers may or may not return additional results contained within the Result struct - this is defined by the handled comand.

Installation

To register handlers with the DI container use the ContainerBuilder or IServiceCollection extension methods provided by the library:

builder.AddResultCommander(assembliesToScan);

To register decorators or adapters use the methods available on ResultCommanderConfiguration like so:

builder.AddResultCommander(assembliesToScan, options => 
{
    options.AddDecorator<FancyDecorator, ISyncCommandHandler<SimpleCommand>();
});

You can register multiple decorators and they'll be applied in the order that you register them - read more at Autofac's docs regarding decorators and adapters.

Example usage

<b> You should never throw exceptions from within handlers, they should be exception free - instead return appropriate error results (and catch possible exceptions).</b> Library offers a simple error catching, logging and exception to result error decorators for uses where writing try-catch blocks becomes a pain - but remember that these results will never be as informative as manually returned proper result error types.

A command without a concrete result:

public SimpleCommand : ICommand
{
    public bool IsSuccess { get; }
    
    public SimpleCommand(bool isSuccess = true)
        => IsSuccess = isSuccess;
}

And a synchronous handler that handles it:

public SimpleSyncCommandHandler : ISyncCommandHandler<SimpleCommand>
{
    Result Handle(SimpleCommand command)
    {
        if (command.IsSuccess)
            return Result.FromSuccess();
            
        return new InvalidOperationError();
    }
}

A command with a concrete result:

public SimpleCommandWithConcreteResult : ICommand<int>
{
    public bool IsSuccess { get; }
    
    public SimpleCommand(bool isSuccess = true)
        => IsSuccess = isSuccess;
}

And a synchronous handler that handles it:

public SimpleSyncCommandHandlerWithConcreteResult : ISyncCommandHandler<SimpleCommand, int>
{
    Result<int> Handle(SimpleCommand command)
    {
        if (command.IsSuccess)
            return 1;
            
        return new InvalidOperationError();
    }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ResultCommander:

Package Downloads
ResultCommander.Autofac

Library featuring a command handler pattern.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.4 243 7/23/2024
2.2.3 311 1/22/2024
2.2.2 297 11/22/2023
2.2.1 194 11/20/2023
2.2.0 179 11/20/2023
2.1.6 275 8/18/2023
2.1.5 269 8/8/2023
2.1.4 265 7/10/2023
2.1.3 264 6/25/2023
2.1.2 444 5/10/2023
2.1.1 307 4/4/2023
2.1.0 353 3/14/2023
2.0.9 362 2/21/2023
2.0.8 416 1/9/2023
2.0.7 386 1/9/2023
2.0.6 480 11/21/2022
2.0.5 425 11/21/2022
2.0.4 434 11/21/2022
2.0.3 452 11/19/2022
2.0.2 430 11/19/2022
2.0.1 423 11/19/2022
2.0.0 418 11/19/2022
1.1.17 525 9/27/2022
1.1.16 497 9/27/2022
1.1.15 550 9/26/2022
1.1.14 534 9/24/2022
1.1.13 502 9/24/2022
1.1.12 545 9/24/2022
1.1.11 533 9/24/2022
1.1.10 537 9/24/2022
1.1.9 534 9/24/2022
1.1.8 521 9/24/2022
1.1.7 519 9/24/2022
1.1.6 522 9/19/2022
1.1.5 538 9/19/2022
1.1.4 528 9/19/2022
1.1.3 523 9/19/2022
1.1.2 534 9/19/2022
1.1.0 542 9/17/2022
1.0.14 524 8/28/2022
1.0.13 516 8/24/2022
1.0.12 517 8/24/2022
1.0.11 513 8/24/2022
1.0.10 495 8/24/2022
1.0.9 499 8/24/2022
1.0.8 523 8/24/2022
1.0.7 522 8/24/2022
1.0.6 526 8/23/2022
1.0.5 511 8/23/2022
1.0.4 510 8/23/2022
1.0.3 505 8/23/2022
1.0.2 514 8/23/2022
1.0.1 514 8/22/2022
1.0.0 512 8/22/2022