Fluens.Kernel
0.6.2
dotnet add package Fluens.Kernel --version 0.6.2
NuGet\Install-Package Fluens.Kernel -Version 0.6.2
<PackageReference Include="Fluens.Kernel" Version="0.6.2" />
<PackageVersion Include="Fluens.Kernel" Version="0.6.2" />
<PackageReference Include="Fluens.Kernel" />
paket add Fluens.Kernel --version 0.6.2
#r "nuget: Fluens.Kernel, 0.6.2"
#:package Fluens.Kernel@0.6.2
#addin nuget:?package=Fluens.Kernel&version=0.6.2
#tool nuget:?package=Fluens.Kernel&version=0.6.2
Fluens.Kernel
DDD building blocks and Result pattern. Zero dependencies.
Installation
dotnet add package Fluens.Kernel
Usage
Result Pattern
// Result without value
Result result = Result.Success();
Result failure = Result.Failure(new NotFoundError("User not found"));
// Result with value
Result<int> result = Result.Success(42);
Result<int> failure = Result.Failure<int>(new ValidationError("Invalid input"));
// Pattern matching
string message = result.Match(
onSuccess: value => $"Got: {value}",
onFailure: error => $"Error: {error.Message}"
);
Both Result and Result<T> are readonly struct types — zero heap allocations, default(Result) is a valid success.
Conversions
// Implicit: value → Result<T>
Result<int> result = 42;
// Explicit: Result<T> → Result (discards value)
Result plain = (Result)result;
// As<T>(): failure Result → Result<T>
Result failure = Result.Failure(new NotFoundError("Missing"));
Result<int> typed = failure.As<int>(); // preserves error
// As<T>() on success throws InvalidOperationException
Built-in error types: NotFoundError, ValidationError, ConflictError, ForbiddenError.
Message Arguments
Errors support parameterized message arguments for translations via MessageArgs and fluent WithArg:
// Create error with message arguments for parameterized translations
var error = new NotFoundError("Order {orderId} not found")
.WithArg("orderId", orderId.ToString());
// Access arguments
error.MessageArgs!["orderId"]; // "123"
// Chain multiple arguments
var error = new Error("CUSTOM", "Hello {name}, you have {count} items")
.WithArg("name", "John")
.WithArg("count", "5");
WithArg is immutable — each call returns a new Error instance without mutating the original. MessageArgs is IReadOnlyDictionary<string, string>? (null by default).
Error Codes
Standard error codes are centralized in the ErrorCodes static class:
ErrorCodes.NotFound // "NOT_FOUND"
ErrorCodes.Validation // "VALIDATION"
ErrorCodes.Conflict // "CONFLICT"
ErrorCodes.Forbidden // "FORBIDDEN"
Use these constants instead of hardcoded strings when comparing error codes:
if (result.Error.Code == ErrorCodes.NotFound)
{
// handle not found
}
DDD Building Blocks
// ITypedIdentifier<out T> is covariant — enables polymorphic identifier handling
public readonly record struct OrderId(int Value) : ITypedIdentifier<int>;
// Entities with identity-based equality
public class Order : AggregateRoot<OrderId>
{
public string Number { get; private set; } = "";
public void Place()
{
AddEvent(new OrderPlacedEvent(ID));
}
}
// Value objects with structural equality
public sealed record Money(decimal Amount, string Currency) : ValueObject
{
protected override IEnumerable<object?> GetAtomicValues()
{
yield return Amount;
yield return Currency;
}
}
Marker interfaces: IAuditable (CreatedAtUtc, UpdatedAtUtc), IDeletable (DeletedAtUtc).
DeletableExtensions
Filter out soft-deleted entities from IQueryable<T> sources:
IQueryable<Order> activeOrders = dbContext.Orders.WithoutDeleted();
WithoutDeleted() returns only entities where DeletedAtUtc is null.
Translatable Messages
TranslatableMessage is a structure for storing translatable content (e.g. audit log entries) as JSON in a database. The message can be translated at read time using a ResourceManager:
// Create a translatable message with arguments
var message = new TranslatableMessage("order.status.changed")
.WithArg("orderId", "ORD-123")
.WithArg("oldStatus", "Pending")
.WithArg("newStatus", "Shipped");
// Serialize to JSON for database storage (compact property names)
var json = JsonSerializer.Serialize(message, TranslatableMessageSerializerContext.Default.TranslatableMessage);
// {"c":"order.status.changed","a":{"orderId":"ORD-123","oldStatus":"Pending","newStatus":"Shipped"}}
// Translate at read time using ResourceManager
var translated = message.Translate(resourceManager, CultureInfo.CurrentUICulture);
// "Order ORD-123 changed from Pending to Shipped"
WithArg is immutable — each call returns a new TranslatableMessage instance. TranslatableMessageSerializerContext provides AOT-compatible JSON serialization with WhenWritingNull to omit null Args.
License
This project is licensed under the MIT License.
| 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 (3)
Showing the top 3 NuGet packages that depend on Fluens.Kernel:
| Package | Downloads |
|---|---|
|
Fluens.Web
ASP.NET Core base types for Fluens web libraries: Result-to-HTTP mapping, global exception handler, and paged responses. |
|
|
Fluens.Cqrs
CQRS pattern implementation with command/query dispatchers, handler interfaces, and logging/tracing decorators. |
|
|
Fluens.Messaging
Inbox/outbox messaging pattern for modular applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.6.2 | 0 | 3/2/2026 |
| 0.6.1 | 0 | 3/2/2026 |
| 0.6.0 | 27 | 3/1/2026 |
| 0.5.7 | 27 | 3/1/2026 |
| 0.5.6 | 30 | 3/1/2026 |
| 0.5.5 | 55 | 2/28/2026 |
| 0.5.4 | 60 | 2/28/2026 |
| 0.5.3 | 64 | 2/27/2026 |
| 0.5.2 | 58 | 2/27/2026 |
| 0.5.1 | 63 | 2/27/2026 |
| 0.5.0 | 68 | 2/26/2026 |
| 0.3.2 | 66 | 2/26/2026 |
| 0.3.1 | 64 | 2/26/2026 |
| 0.3.0 | 74 | 2/24/2026 |
| 0.2.5 | 80 | 2/24/2026 |
| 0.2.4 | 71 | 2/24/2026 |
| 0.2.3 | 65 | 2/24/2026 |
| 0.1.0 | 74 | 2/23/2026 |