CSharpEssentials.AspNetCore
2.1.0
dotnet add package CSharpEssentials.AspNetCore --version 2.1.0
NuGet\Install-Package CSharpEssentials.AspNetCore -Version 2.1.0
<PackageReference Include="CSharpEssentials.AspNetCore" Version="2.1.0" />
<PackageVersion Include="CSharpEssentials.AspNetCore" Version="2.1.0" />
<PackageReference Include="CSharpEssentials.AspNetCore" />
paket add CSharpEssentials.AspNetCore --version 2.1.0
#r "nuget: CSharpEssentials.AspNetCore, 2.1.0"
#:package CSharpEssentials.AspNetCore@2.1.0
#addin nuget:?package=CSharpEssentials.AspNetCore&version=2.1.0
#tool nuget:?package=CSharpEssentials.AspNetCore&version=2.1.0
CSharpEssentials
CSharpEssentials is a comprehensive ecosystem of .NET libraries designed to modernize C# development. It bridges the gap between Object-Oriented and Functional Programming, providing robust tools for error handling, domain modeling, and enterprise application development.
Goal: Make C# code more expressive, safer, and easier to test without sacrificing performance.
📦 Ecosystem Overview
CSharpEssentials is modular. You can use the meta-package to get everything, or install specific modules to keep dependencies light.
| Package | Description | NuGet |
|---|---|---|
| CSharpEssentials | The meta-package including all core functional modules and exclusive bridge extensions. | |
| CSharpEssentials.Core | Foundational extensions, guard clauses, and utilities (Strings, Collections, GUIDs). | |
| CSharpEssentials.Results | Railway-oriented programming with Result and Result<T> patterns. |
|
| CSharpEssentials.Maybe | Maybe<T> monad for null-safe optional value handling. |
|
| CSharpEssentials.Errors | Structured error handling with unique codes and standard types (NotFound, Validation, etc.). | |
| CSharpEssentials.Rules | Composable business rule engine (And, Or, Linear, Conditional logic). | |
| CSharpEssentials.Any | Discriminated Unions (Any<T1, T2, ...>) for type-safe polymorphic returns. |
|
| CSharpEssentials.Entity | Domain-Driven Design base classes (EntityBase, SoftDeletableEntityBase). |
|
| CSharpEssentials.EntityFrameworkCore | EF Core extensions, Interceptors (Slow Query), and Pagination support. | |
| CSharpEssentials.AspNetCore | Web API utilities: Global Exception Handler, Problem Details, API Versioning. | |
| CSharpEssentials.Json | Advanced JSON serialization: Polymorphism, String Enums, Multi-format Dates. | |
| CSharpEssentials.Time | Testable IDateTimeProvider abstraction and extensions. |
|
| CSharpEssentials.RequestResponseLogging | Highly configurable HTTP traffic logging middleware. | |
| CSharpEssentials.GcpSecretManager | Google Cloud Secret Manager integration for IConfiguration. | |
| CSharpEssentials.Clone | Type-safe deep cloning interfaces and extensions. | |
| CSharpEssentials.Enums | Attributes for controlling Enum serialization behavior. |
🚀 Getting Started
Install the main package to get the core functional tools:
dotnet add package CSharpEssentials
Or pick individual packages as needed (e.g., dotnet add package CSharpEssentials.Results).
💡 Feature Highlights
1. Functional Error Handling (Results & Errors)
Stop throwing exceptions for flow control. Use Result<T> to express success or failure explicitly.
using CSharpEssentials.ResultPattern;
using CSharpEssentials.Errors;
public Result<User> RegisterUser(string email)
{
if (string.IsNullOrEmpty(email))
return Error.Validation("User.EmailRequired", "Email cannot be empty.");
if (_repo.Exists(email))
return Error.Conflict("User.Exists", "User already exists.");
var user = new User(email);
return user; // Implicit conversion to Result<User>
}
2. Safe Optionals (Maybe)
Eliminate NullReferenceException by explicitly modeling the absence of a value.
using CSharpEssentials.Maybe;
public Maybe<User> GetUserById(Guid id)
{
var user = _repo.Find(id);
return user; // Implicit conversion from User?
}
// Chaining with LINQ
var zipCode = GetUserById(id)
.Map(u => u.Address)
.Map(a => a.ZipCode)
.GetValueOrDefault("00000");
3. Business Rules Engine
Compose complex logic from simple, reusable rules.
var rule = Rule.And(
new MinimumAgeRule(18),
new KycCompletedRule()
);
var result = RuleEngine.Evaluate(rule, userContext);
4. Robust Web APIs (AspNetCore)
Automatically convert Result failures into standard RFC 7807 Problem Details responses using the Global Exception Handler.
// Program.cs
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();
builder.Services.AddEnhancedProblemDetails();
// Controller
[HttpPost]
public IActionResult Create(CreateUserRequest request)
{
Result<User> result = _service.Create(request);
// Returns 200 OK with data, or 400/404/409 ProblemDetails based on Error Type
return result.ToActionResult();
}
5. Domain Modeling (Entity)
Build rich domain models with built-in Audit logs and Domain Events.
public class Order : EntityBase<Guid>
{
public void MarkAsPaid()
{
Status = OrderStatus.Paid;
Raise(new OrderPaidEvent(Id)); // Domain Event
SetUpdatedInfo(DateTimeOffset.UtcNow, "System"); // Auditing
}
}
🛠️ Development & Publishing
This repository includes a smart build script (build-and-publish-nugets.sh) that manages dependency orders and versioning for all packages.
# Build and Test all packages
./build-and-publish-nugets.sh
# Publish to NuGet (requires API Key)
./build-and-publish-nugets.sh --parallel YOUR_API_KEY
🤝 Contributing
Contributions are welcome! Please read our CONTRIBUTING.md guide.
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
🙏 Acknowledgments
Inspired by excellent community projects like ErrorOr, CSharpFunctionalExtensions, and OneOf.
| 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
- Asp.Versioning.Http (>= 8.1.0)
- Asp.Versioning.Mvc (>= 8.1.0)
- Asp.Versioning.Mvc.ApiExplorer (>= 8.1.0)
- CSharpEssentials.Errors (>= 2.1.0)
- CSharpEssentials.Json (>= 2.1.0)
- CSharpEssentials.Results (>= 2.1.0)
- Swashbuckle.AspNetCore (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.0 | 162 | 11/26/2025 |
| 2.0.9 | 188 | 9/30/2025 |
| 2.0.8 | 183 | 9/29/2025 |
| 2.0.7 | 169 | 9/29/2025 |
| 2.0.6 | 168 | 9/29/2025 |
| 2.0.5 | 171 | 9/29/2025 |
| 2.0.4 | 172 | 9/28/2025 |
| 2.0.3 | 167 | 9/28/2025 |
| 2.0.2 | 165 | 9/28/2025 |
| 2.0.1 | 165 | 9/28/2025 |
| 2.0.0 | 174 | 9/28/2025 |
| 1.0.15 | 357 | 2/4/2025 |
| 1.0.14 | 217 | 1/29/2025 |
| 1.0.13 | 155 | 12/27/2024 |
| 1.0.12 | 151 | 12/18/2024 |
| 1.0.11 | 140 | 12/18/2024 |
| 1.0.10 | 152 | 12/17/2024 |
| 1.0.9 | 154 | 12/15/2024 |
| 1.0.8 | 162 | 12/15/2024 |
| 1.0.7 | 152 | 12/12/2024 |
| 1.0.6 | 137 | 12/11/2024 |
| 1.0.5 | 134 | 12/11/2024 |
| 1.0.4 | 136 | 12/10/2024 |
| 1.0.3 | 120 | 12/10/2024 |
| 1.0.2 | 147 | 12/6/2024 |
| 1.0.1 | 141 | 12/6/2024 |
| 1.0.0 | 163 | 12/4/2024 |