Orleans.FluentResults
7.1.5
dotnet add package Orleans.FluentResults --version 7.1.5
NuGet\Install-Package Orleans.FluentResults -Version 7.1.5
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="Orleans.FluentResults" Version="7.1.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Orleans.FluentResults --version 7.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Orleans.FluentResults, 7.1.5"
#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.
// Install Orleans.FluentResults as a Cake Addin #addin nuget:?package=Orleans.FluentResults&version=7.1.5 // Install Orleans.FluentResults as a Cake Tool #tool nuget:?package=Orleans.FluentResults&version=7.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Fluent Results Pattern for Microsoft Orleans
Samples first:
public Task<Result<bool>> InitializeAsync(SnackMachineInitializeCommand cmd)
{
var id = this.GetPrimaryKey();
return Result.Ok()
.Ensure(State.IsDeleted == false, $"Snack machine {id} has already been removed.")
.TapErrorTryAsync(errors => PublishErrorAsync(new SnackMachineErrorOccurredEvent(id, ErrorCodes.SnackMachineRemoved.Value, errors.ToReasons(), cmd.TraceId, DateTimeOffset.UtcNow, cmd.OperatedBy, Version)))
.EnsureAsync(State.IsCreated == false, $"Snack machine {id} already exists.")
.TapErrorTryAsync(errors => PublishErrorAsync(new SnackMachineErrorOccurredEvent(id, ErrorCodes.SnackMachineExists.Value, errors.ToReasons(), cmd.TraceId, DateTimeOffset.UtcNow, cmd.OperatedBy, Version)))
.BindTryAsync(() => PublishPersistedAsync(new SnackMachineInitializedEvent(id, cmd.MoneyInside, cmd.Slots, cmd.TraceId, DateTimeOffset.UtcNow, cmd.OperatedBy, Version)));
}
protected Task<Result<bool>> PublishPersistedAsync(DomainEvent evt)
{
return Result.Ok()
.MapTryAsync(() => RaiseConditionalEvent(evt))
.MapTryIfAsync(raised => raised, _ => PersistAsync(evt))
.TapTryAsync(() => _stream.OnNextAsync(evt with { Version = Version }, new EventSequenceTokenV2(Version)));
}
Explanation of the above steps:
- Ensure is used to check a known condition. If successful, the input result of the previous step is passed directly to the next step, otherwise the failure result is passed with the specified error message attached.
- TapError is used to execute a specified operation when the previous step has an error input. If the previous step input is a successful result, no operation is performed. Regardless of the operation result, the input result of the previous step is passed directly to the next step (this is a feature of the Tap series).
- TapErrorTryAsync is used for executing asynchronous operations and uses Try/Catch internally. Asynchronous operations do not need to specify async/await as the internal process will automatically determine whether to wait or not. Asynchronous operations are classified into two categories:
- If the method body requires the use of asynchronous operations, the method must be marked as Async.
- If the input result of the previous step is asynchronous, the method must also be marked as Async.
- Bind is used when the output result needs to be converted. If the input to the method body is another Result<TOther>, the output result is also Result<TOther>.
Product | Versions 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
- Microsoft.Orleans.Sdk (>= 7.1.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Add checking Task.IsCompleted flag.