ResultCommander 1.0.0
See the version list below for details.
dotnet add package ResultCommander --version 1.0.0
NuGet\Install-Package ResultCommander -Version 1.0.0
<PackageReference Include="ResultCommander" Version="1.0.0" />
paket add ResultCommander --version 1.0.0
#r "nuget: ResultCommander, 1.0.0"
// Install ResultCommander as a Cake Addin #addin nuget:?package=ResultCommander&version=1.0.0 // Install ResultCommander as a Cake Tool #tool nuget:?package=ResultCommander&version=1.0.0
ResultCommander
Library featuring a command handler pattern for both synchronous and asynchronous operations.
Utilizes Autofac thus Autofac is required and a functional result approach for failure-prone operations.
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
Since the library utilizes Autofac, base Autofac configuration is required to use command handlers - Autofac's docs.
To register handlers with the DI container use the ContainerBuilder extension method provided by the library:
builder.AddCommandHandlers();
To register decorators or adapters use the methods available on CommanderConfiguration like so:
builder.AddCommandHandlers(options =>
{
options.AddDecorator<FancyDecorator, SimpleHandler>();
});
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
-
net6.0
- Microsoft.Extensions.Options (>= 6.0.0)
- MikyM.Autofac.Extensions (>= 1.0.8)
- MikyM.Common.Utilities (>= 1.1.1)
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 | 168 | 7 months ago |
2.2.3 | 259 | 1/22/2024 |
2.2.2 | 265 | 11/22/2023 |
2.2.1 | 156 | 11/20/2023 |
2.2.0 | 152 | 11/20/2023 |
2.1.6 | 211 | 8/18/2023 |
2.1.5 | 203 | 8/8/2023 |
2.1.4 | 203 | 7/10/2023 |
2.1.3 | 188 | 6/25/2023 |
2.1.2 | 237 | 5/10/2023 |
2.1.1 | 223 | 4/4/2023 |
2.1.0 | 271 | 3/14/2023 |
2.0.9 | 280 | 2/21/2023 |
2.0.8 | 333 | 1/9/2023 |
2.0.7 | 299 | 1/9/2023 |
2.0.6 | 399 | 11/21/2022 |
2.0.5 | 346 | 11/21/2022 |
2.0.4 | 363 | 11/21/2022 |
2.0.3 | 368 | 11/19/2022 |
2.0.2 | 348 | 11/19/2022 |
2.0.1 | 343 | 11/19/2022 |
2.0.0 | 338 | 11/19/2022 |
1.1.17 | 435 | 9/27/2022 |
1.1.16 | 420 | 9/27/2022 |
1.1.15 | 458 | 9/26/2022 |
1.1.14 | 457 | 9/24/2022 |
1.1.13 | 414 | 9/24/2022 |
1.1.12 | 459 | 9/24/2022 |
1.1.11 | 444 | 9/24/2022 |
1.1.10 | 448 | 9/24/2022 |
1.1.9 | 446 | 9/24/2022 |
1.1.8 | 432 | 9/24/2022 |
1.1.7 | 429 | 9/24/2022 |
1.1.6 | 434 | 9/19/2022 |
1.1.5 | 447 | 9/19/2022 |
1.1.4 | 434 | 9/19/2022 |
1.1.3 | 437 | 9/19/2022 |
1.1.2 | 433 | 9/19/2022 |
1.1.0 | 461 | 9/17/2022 |
1.0.14 | 434 | 8/28/2022 |
1.0.13 | 427 | 8/24/2022 |
1.0.12 | 429 | 8/24/2022 |
1.0.11 | 425 | 8/24/2022 |
1.0.10 | 416 | 8/24/2022 |
1.0.9 | 422 | 8/24/2022 |
1.0.8 | 427 | 8/24/2022 |
1.0.7 | 425 | 8/24/2022 |
1.0.6 | 429 | 8/23/2022 |
1.0.5 | 420 | 8/23/2022 |
1.0.4 | 429 | 8/23/2022 |
1.0.3 | 427 | 8/23/2022 |
1.0.2 | 424 | 8/23/2022 |
1.0.1 | 436 | 8/22/2022 |
1.0.0 | 420 | 8/22/2022 |