RA.Utilities.Core.Results
10.0.2
Prefix Reserved
dotnet add package RA.Utilities.Core.Results --version 10.0.2
NuGet\Install-Package RA.Utilities.Core.Results -Version 10.0.2
<PackageReference Include="RA.Utilities.Core.Results" Version="10.0.2" />
<PackageVersion Include="RA.Utilities.Core.Results" Version="10.0.2" />
<PackageReference Include="RA.Utilities.Core.Results" />
paket add RA.Utilities.Core.Results --version 10.0.2
#r "nuget: RA.Utilities.Core.Results, 10.0.2"
#:package RA.Utilities.Core.Results@10.0.2
#addin nuget:?package=RA.Utilities.Core.Results&version=10.0.2
#tool nuget:?package=RA.Utilities.Core.Results&version=10.0.2
RA.Utilities.Core.Results
RA.Utilities.Core.Results is a lightweight .NET library designed to enhance error handling by providing a functional Result type. It helps you write cleaner, more predictable, and more robust code by avoiding exceptions for expected operational failures.
🚀 Getting Started
Install the package via the .NET CLI:
dotnet add package RA.Utilities.Core.Results
✨ Key Features
Functional Result and Result<T> Types
The library provides two core types for handling outcomes:
Result: For operations that succeed or fail without returning a value (e.g., saving to a database).Result<T>: For operations that return a value on success.
These types make the intent of your code explicit by forcing you to handle both success and failure paths, preventing unhandled errors.
public Result<User> FindUser(int userId)
{
var user = _userRepository.GetById(userId);
if (user is null)
{
return new NotFoundException("User not found."); // Implicit conversion to Failure
}
return user; // Implicit conversion to Success
}
The Match method ensures that both success and failure cases are handled:
var result = FindUser(123);
return result.Match(
success: user => Ok(user),
failure: exception => NotFound(exception.Message)
);
Railway-Oriented Programming Extensions
Chain multiple fallible operations together using a fluent, readable API. The chain short-circuits on the first failure, passing the error down the line.
The extension methods live in the RA.Utilities.Core.Results.Extensions namespace — add using RA.Utilities.Core.Results.Extensions; (alongside using RA.Utilities.Core.Results;) to use them.
Map(): Transforms the value inside a successfulResult<T>.Bind(): Chains another function that returns aResult.OnSuccess()/OnFailure(): Executes side-effects like logging without altering the result.
public Result<string> GetAdminEmail(int userId)
{
return FindUser(userId)
.Bind(user => EnsureIsAdmin(user))
.Map(adminUser => adminUser.Email)
.OnSuccess(email => _logger.LogInformation("Admin email found for user {UserId}", userId))
.OnFailure(ex => _logger.LogError(ex, "Failed to get admin email for user {UserId}", userId));
}
Asynchronous Support
All extension methods have async counterparts (MapAsync, BindAsync, etc.) to integrate seamlessly into asynchronous workflows.
var result = await FindUserAsync(userId)
.BindAsync(user => ValidatePermissionsAsync(user));
Additional documentation
For more information on how this package fits into the larger RA.Utilities ecosystem, please see the main repository documentation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on RA.Utilities.Core.Results:
| Package | Downloads |
|---|---|
|
RA.Utilities.Dispatcher
Provides a lightweight, source-generated mediator (dispatcher) for CQRS, including Result-based request and notification dispatch, pipeline behaviors, validation, and automatic handler registration. |
GitHub repositories
This package is not used by any popular GitHub repositories.