ResultCommander.Autofac
2.2.0
See the version list below for details.
dotnet add package ResultCommander.Autofac --version 2.2.0
NuGet\Install-Package ResultCommander.Autofac -Version 2.2.0
<PackageReference Include="ResultCommander.Autofac" Version="2.2.0" />
paket add ResultCommander.Autofac --version 2.2.0
#r "nuget: ResultCommander.Autofac, 2.2.0"
// Install ResultCommander.Autofac as a Cake Addin #addin nuget:?package=ResultCommander.Autofac&version=2.2.0 // Install ResultCommander.Autofac as a Cake Tool #tool nuget:?package=ResultCommander.Autofac&version=2.2.0
ResultCommander
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.
Documentation
Documentation available at https://mikym.github.io/ResultCommander/.
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 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 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. |
-
net6.0
- AttributeBasedRegistration.Autofac (>= 2.2.0)
- Autofac (>= 7.1.0)
- ResultCommander (>= 2.2.0)
-
net7.0
- AttributeBasedRegistration.Autofac (>= 2.2.0)
- Autofac (>= 7.1.0)
- ResultCommander (>= 2.2.0)
-
net8.0
- AttributeBasedRegistration.Autofac (>= 2.2.0)
- Autofac (>= 7.1.0)
- ResultCommander (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.