NPv.ResultPattern
1.0.0
dotnet add package NPv.ResultPattern --version 1.0.0
NuGet\Install-Package NPv.ResultPattern -Version 1.0.0
<PackageReference Include="NPv.ResultPattern" Version="1.0.0" />
<PackageVersion Include="NPv.ResultPattern" Version="1.0.0" />
<PackageReference Include="NPv.ResultPattern" />
paket add NPv.ResultPattern --version 1.0.0
#r "nuget: NPv.ResultPattern, 1.0.0"
#:package NPv.ResultPattern@1.0.0
#addin nuget:?package=NPv.ResultPattern&version=1.0.0
#tool nuget:?package=NPv.ResultPattern&version=1.0.0
NPv.ResultPattern
Minimal Result pattern implementation for .NET.
A lightweight alternative to exceptions for expected business and validation errors.
Features
- ✅
Result
(success/failure without value) - ✅
Result<T>
(success/failure with value) - ✅ Multiple errors support (
Result.Failure(params Error[])
) - ✅ Strongly typed
Error
records with code and property name - ✅ Implicit conversions for cleaner syntax (
T → Result<T>
,Error → Result<T>
) - ✅ Works with validation and business rules
Example
Defining reusable errors
It’s possible to place error catalogs (e.g. DbErrors
) into a shared domain library such as NPv.Domain.Abstractions:
public static class DbErrors
{
public static readonly Error EntityNotFound =
new("DbErrors.EntityNotFound", "EntityId");
public static readonly Error EntityAlreadyExists =
new("DbErrors.EntityAlreadyExists", "EntityId");
}
Returning results from commands
public async Task<Result<User>> CreateUserAsync(string email)
{
if (string.IsNullOrWhiteSpace(email))
return new Error("Validation.Required", "Email");
if (await _db.Users.AnyAsync(u => u.Email == email))
return DbErrors.EntityAlreadyExists;
var user = new User { Email = email };
_db.Users.Add(user);
return Result<User>.Success(user);
}
🚀 Author's Note
This library grew out of my long-standing personal interest in structuring and publishing open source packages. Over time, I’ve revisited and refined earlier internal utilities and ideas, giving them a more consistent shape and preparing them for wider reuse. Along the way, I’ve also taken the opportunity to explore how open source distribution and licensing work in the .NET ecosystem.
It’s a small step toward something I’ve always wanted to try — sharing practical, minimal tools that reflect years of learning, experimentation, and refinement.
Hopefully, someone finds it useful.
Nikolai 😛
⚖️ License
MIT — you are free to use this in commercial and open-source software.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on NPv.ResultPattern:
Package | Downloads |
---|---|
NPv.CQS.Infrastructure
Provides command and query execution infrastructure for CQS-based applications, with builder implementations. |
|
NPv.CQS.Abstractions
Minimal abstractions for building CQS-compliant applications. Contains ICommand, IQuery, ICriterion and builder interfaces for declarative handler invocation. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 375 | 9/22/2025 |