A lightweight and expressive result-handling package for .NET applications.
✨ Clean. Explicit. Production-ready.
Stop returning raw exceptions for expected outcomes.
Stop mixing business logic with HTTP responses.
Start modeling results explicitly.
📦 NuGet: https://www.nuget.org/packages/IResultPattern/
IResultPattern is a dependency-free result modeling library for .NET. It gives you a consistent, strongly-typed way to represent operation outcomes across application layers.
Instead of throwing exceptions for flow control or returning loosely structured responses, you return explicit, predictable results.
- ASP.NET Core Web APIs
- Clean Architecture
- Domain-Driven Design (DDD)
- Microservices
- Event-driven systems
- Modular monoliths
dotnet add package IResultPatternusing IMustafaZeynali.IResultPattern;Statuses are aligned with HTTP semantics:
| Status | Code |
|---|---|
| Success | 200 |
| Created | 201 |
| NoContent | 204 |
| BadRequest | 400 |
| Unauthorized | 401 |
| Forbidden | 403 |
| NotFound | 404 |
| Conflict | 409 |
| ValidationError | 422 |
| InternalServerError | 500 |
| ServiceUnavailable | 503 |
Result // no payload
Result<TData> // single item
ResultList<TData> // collection + paginationTData must be a reference type (class).
ResultList<T> implements IPageInfo with:
TotalItemCountPageCountPageNumberPageSize
- Separates business outcomes from transport concerns
- Improves readability and testability
- Reduces exception misuse
- Provides a consistent response contract
- No external dependencies
- Targets
netstandard2.1 - Explicit factory methods — no hidden magic
The legacy Failure(string) overloads remain available and are marked [Obsolete]. Prefer specific status methods instead.
Exceptions should represent exceptional conditions — not validation failures or other predictable outcomes.
This package encourages:
- Explicit business outcomes
- Better error handling
- Consistent API behavior
- Easier testing
- Clearer code semantics
return Result.Success();
return Result.NotFound("User not found");
return Result.ValidationError("Email is required");return Result<User>.Success(user);
return Result<User>.NotFound("User not found");
return Result<User>.ValidationError("Email is required");return ResultList<User>.Success(users, totalItemCount: 120);
return ResultList<User>.Success(users, pageInfo);
return ResultList<User>.NotFound("No users found");
return ResultList<User>.ValidationError("Invalid page size");Result result = ResultStatus.NotFound; // failure statuses
Result<User> ok = user; // wraps as SuccessDevelopers who:
- Care about clean, explicit code
- Use DDD or Clean Architecture
- Want expressive application flow
- Build scalable APIs and services
Licensed under the Apache License 2.0.
Found a bug or have an idea?
Open an issue: https://github.com/IMustafaZeynali/IResultPattern/issues