Xpandables.Entities.Data
10.0.0
dotnet add package Xpandables.Entities.Data --version 10.0.0
NuGet\Install-Package Xpandables.Entities.Data -Version 10.0.0
<PackageReference Include="Xpandables.Entities.Data" Version="10.0.0" />
<PackageVersion Include="Xpandables.Entities.Data" Version="10.0.0" />
<PackageReference Include="Xpandables.Entities.Data" />
paket add Xpandables.Entities.Data --version 10.0.0
#r "nuget: Xpandables.Entities.Data, 10.0.0"
#:package Xpandables.Entities.Data@10.0.0
#addin nuget:?package=Xpandables.Entities.Data&version=10.0.0
#tool nuget:?package=Xpandables.Entities.Data&version=10.0.0
<div align="center">
๐ฆ Xpandables.Net
A comprehensive, modular .NET library for building modern, scalable applications with clean architecture patterns
Features โข Getting Started โข Documentation โข Real-World Example โข Architecture โข Contributing
</div>
๐ Overview
Xpandables.Net is a powerful, production-ready library ecosystem designed to accelerate .NET application development while promoting best practices, clean architecture, and maintainable code. Built with .NET 10 and leveraging the latest C# language features, it provides a rich set of tools for enterprise-grade applications.
๐ก Philosophy
- ๐งฉ Modular Design: Pick only what you need - each package is independently versioned and maintained
- โก Performance First: Built for high-performance scenarios with AOT compatibility
- ๐ Type Safety: Leverage strong typing to catch errors at compile time
- โ Testability: Designed with unit testing and integration testing in mind
- ๐ Well Documented: Comprehensive XML documentation for IntelliSense support
๐ฏ Key Features
Core Capabilities
| Feature | Description | Package |
|---|---|---|
| โ Operation Results | Robust error handling with HTTP-aware result types | System.Results |
| ๐ Optional Values | Null-safe optional value handling (like Rust's Option) | System.Optionals |
| ๐ก Mediator Pattern | CQRS and request/response pipeline implementation | System.Results.Tasks |
| ๐ Pipeline Decorators | Validation, transaction, and event decorators | System.Results.Pipelines |
| โ๏ธ Validation | Flexible validation framework with specifications | System.Validation |
| ๐พ Repository Pattern | Generic repository with unit of work support | System.Entities.Data |
| ๐ REST Client | Type-safe, attribute-based HTTP client | System.Rests |
| ๐ Event Sourcing | Complete event sourcing with W3C trace context support | System.Events |
| ๐๏ธ Event Store | EF Core event store with outbox pattern | System.Events.Data |
| ๐ Async Paging | Asynchronous enumerable extensions and pagination | System.AsyncPaged |
| ๐ W3C Trace Context | Distributed tracing with traceparent header support | AspNetCore.Events |
๐ Getting Started
Prerequisites
- .NET 10 SDK or later
- Visual Studio 2026 (or later) or JetBrains Rider 2025.3+ (recommended)
- Basic understanding of C# and async/await patterns
Installation
Install the packages you need via NuGet Package Manager:
# Core operation result handling
dotnet add package System.Results
# Optional value handling
dotnet add package System.Optionals
# Mediator and pipeline support
dotnet add package System.Results.Tasks
# Pipeline decorators
dotnet add package System.Results.Pipelines
# Validation framework
dotnet add package System.Validation
# Repository pattern with EF Core
dotnet add package System.Entities.Data
# REST client
dotnet add package System.Rests
# Event sourcing
dotnet add package System.Events
dotnet add package System.Events.Data
# Async paging
dotnet add package System.AsyncPaged
dotnet add package System.AsyncPaged.Linq
dotnet add package System.AsyncPaged.Json
# ASP.NET Core integration
dotnet add package AspNetCore.Net
dotnet add package AspNetCore.AsyncPaged
dotnet add package AspNetCore.Events
dotnet add package AspNetCore.Results
dotnet add package AspNetCore.Composition
Quick Example
using System.Results;
using System.Results.Requests;
using System.Optionals;
// Define a request
public sealed record GetUserQuery(Guid UserId) : IRequest<User>;
// Handle the request
public sealed class GetUserHandler : IRequestHandler<GetUserQuery, User>
{
private readonly IUserRepository _repository;
public GetUserHandler(IUserRepository repository)
=> _repository = repository;
public async Task<Result<User>> HandleAsync(
GetUserQuery request,
CancellationToken cancellationToken)
{
// Fetch user with Optional to handle null cases
Optional<User> user = await _repository
.FindByIdAsync(request.UserId, cancellationToken);
return user
.Map(u => Result.Success(u))
.Empty(() => Result
.NotFound<User>("userId", "User not found"));
}
}
๐ผ Real-World Example
This repository includes a complete Event Sourcing Banking Sample API that demonstrates how to build a production-ready application using Xpandables.Net. See the SampleApi README for a detailed walkthrough.
Sample API Highlights
The Xpandables.Net.SampleApi project showcases:
โ
Event Sourcing & CQRS - Complete bank account management with domain events
โ
Minimal API Endpoints - Clean, modular endpoint definitions with IEndpointRoute
โ
EF Core Integration - Event store and outbox pattern with SQL Server
โ
Swagger Documentation - Fully documented API with OpenAPI support
โ
Docker Support - Production-ready containerization
Running the Sample
# Clone the repository
git clone https://github.com/Francescolis/Xpandables.Net.git
cd Xpandables.Net
# Navigate to sample project
cd Xpandables.Net.SampleApi
# Update connection string in appsettings.json
# Run migrations (automatic on startup)
# Run the application
dotnet run
# Navigate to Swagger UI
# https://localhost:5001/swagger
Key Files to Explore:
Program.cs- Application setup with event sourcingBankAccounts/Features/CreateBankAccount/- Complete CQRS command exampleEventStorage/- Event store and outbox configuration
๐ Documentation
Package Documentation
Each package has detailed documentation with examples and API references:
Foundation Packages
- ๐ง System.Primitives - Core primitives and utilities
- โ System.Results - Operation result handling with request/handler pattern
- ๐ System.Optionals - Null-safe optional value types
Application Layer
- ๐ก System.Results.Tasks - Mediator pattern and request dispatching
- ๐ System.Results.Pipelines - Pipeline decorators for validation, transactions, events
- โ๏ธ System.Validation - Specification pattern and rule validators
- ๐งฉ System.Composition - MEF-based service composition
Data Access
- ๐พ System.Entities.Data - EF Core repository with DataContext
Event Handling
- ๐ System.Events - Event sourcing and domain events
- ๐๏ธ System.Events.Data - EF Core event store implementation
HTTP & REST
- ๐ System.Rests - Type-safe REST client with attribute-based routing
Async & Utilities
- ๐ System.AsyncPaged - Async paged collections
- ๐ System.AsyncPaged.Linq - LINQ extensions for async paging
- ๐ System.AsyncPaged.Json - JSON serialization for paged data
ASP.NET Core Integration
- ๐ AspNetCore.Net - ASP.NET Core minimal API with endpoint routing
- ๐ AspNetCore.AsyncPaged - Async paged response formatters
- ๐ AspNetCore.Events - W3C trace context middleware
- โ AspNetCore.Results - Result type HTTP integrations
- ๐ AspNetCore.Composition - MEF service composition
๐๏ธ Architecture
Xpandables.Net follows clean architecture principles with clear separation of concerns:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Presentation Layer โ
โ (AspNetCore.Net, AspNetCore.Events, โ
โ AspNetCore.AsyncPaged, โ
โ AspNetCore.Results) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Application Layer โ
โ (System.Results, System.Results.Tasks, โ
โ System.Results.Pipelines, โ
โ System.Composition) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Domain Layer โ
โ (System.Events, System.Optionals, โ
โ System.Primitives, System.Validation, โ
โ System.AsyncPaged) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Infrastructure Layer โ
โ (System.Entities.Data, System.Events. โ
โ Data, System.Rests, โ
โ System.AsyncPaged.Linq) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Design Patterns Implemented
- ๐ Repository Pattern - Abstraction over data access
- ๐ Unit of Work - Transaction management
- ๐ก Mediator Pattern - Decoupled request handling
- ๐จ Decorator Pattern - Pipeline behaviors
- ๐ Specification Pattern - Business rule encapsulation
- ๐ Event Sourcing - Event-driven architecture
- ๐ CQRS - Command Query Responsibility Segregation
- โ Result Pattern - Functional error handling
๐ Highlights
1. Operation Results - Railway Oriented Programming
using System.Results;
public async Task<Result<Order>> CreateOrderAsync(CreateOrderRequest request)
{
// Validate
if (string.IsNullOrEmpty(request.CustomerId))
return Result.Failure<Order>("customerId", "Customer ID is required");
// Create order
var order = new Order { CustomerId = request.CustomerId };
await _repository.AddAsync(order);
return Result.Created(order)
.WithLocation($"/api/orders/{order.Id}");
}
2. Type-Safe REST Client
using System.Rests;
[RestPost("/api/users")]
public sealed record CreateUserRequest(string Name, string Email)
: IRestRequest<User>, IRestString;
var response = await _restClient.SendAsync(
new CreateUserRequest("John", "john@example.com"));
var user = response.Result;
3. Fluent Validation with Specifications
using System.ComponentModel.DataAnnotations;
// Create specifications using factory methods
var nameSpec = Specification.IsNotNull<User, string>(u => u.Name);
var emailSpec = Specification.Contains<User>(u => u.Email, "@");
var ageSpec = Specification.GreaterThan<User, int>(u => u.Age, 18);
// Combine specifications
var validUser = Specification.All(nameSpec, emailSpec, ageSpec);
// Check if satisfied
if (validUser.IsSatisfiedBy(user))
{
Console.WriteLine("User meets all criteria");
}
// Use in LINQ queries
var activeAdults = users.Where(validUser.Expression.Compile());
4. Event Sourcing with Aggregates
using System.Events.Aggregates;
public sealed class OrderAggregate : Aggregate
{
public string OrderNumber { get; private set; } = string.Empty;
public decimal TotalAmount { get; private set; }
public static OrderAggregate Create(string orderNumber, decimal amount)
{
var aggregate = new OrderAggregate();
aggregate.AppendEvent(new OrderCreatedEvent
{
OrderNumber = orderNumber,
Amount = amount
});
return aggregate;
}
public void AddItem(string productId, decimal price)
{
AppendEvent(new ItemAddedEvent { ProductId = productId, Price = price });
}
// Event handlers (called automatically)
private void On(OrderCreatedEvent evt)
{
OrderNumber = evt.OrderNumber;
TotalAmount = evt.Amount;
}
private void On(ItemAddedEvent evt)
{
TotalAmount += evt.Price;
}
}
// Usage
var order = OrderAggregate.Create("ORD-001", 100m);
order.AddItem("PROD-1", 25m);
await _aggregateStore.AppendAsync(order);
5. W3C Trace Context for Distributed Tracing
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Register event context with W3C trace support
builder.Services.AddXEventContext();
builder.Services.AddXEventContextMiddleware();
var app = builder.Build();
// Middleware reads traceparent header (W3C format) and establishes EventContext
app.UseXEventContextMiddleware();
app.MapPost("/api/orders", async (
CreateOrderRequest request,
IEventContextAccessor context,
CancellationToken ct) =>
{
// CorrelationId is automatically populated from traceparent header
// or Activity.Current.Id, or generated as GUID string
var correlationId = context.Current.CorrelationId; // W3C trace ID string
// Events inherit correlation/causation for distributed tracing
var order = OrderAggregate.Create(request.OrderNumber, request.Amount);
await orderStore.SaveAsync(order, ct);
return Results.Created($"/api/orders/{order.StreamId}", order);
});
app.Run();
๐งช Testing
The library includes comprehensive unit tests demonstrating usage patterns:
# Run all tests
dotnet test
# Run specific test project
dotnet test Xpandables.Net.UnitTests
๐ฆ All Packages
| Package | Description |
|---|---|
| System.Results | Operation result types with request/handler pattern |
| System.Results.Tasks | Mediator for dispatching requests to handlers |
| System.Results.Pipelines | Pipeline decorators (validation, transactions, events) |
| System.Optionals | Null-safe optional value handling |
| System.Primitives | Core primitives and utilities |
| System.Validation | Specification pattern and rule validators |
| System.Composition | MEF-based service composition |
| System.Events | Domain events and event sourcing with W3C trace IDs |
| System.Events.Data | EF Core event store with outbox pattern |
| System.Entities.Data | EF Core repository with DataContext |
| System.Rests | Type-safe REST client |
| System.AsyncPaged | Async paged collections |
| System.AsyncPaged.Linq | LINQ extensions for async paging |
| System.AsyncPaged.Json | JSON serialization for paged data |
| AspNetCore.Net | ASP.NET Core minimal API integrations |
| AspNetCore.AsyncPaged | ASP.NET Core async paged response formatters |
| AspNetCore.Events | W3C trace context middleware for event correlation |
| AspNetCore.Results | ASP.NET Core result type integrations |
| AspNetCore.Composition | MEF-based ASP.NET Core service composition |
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
Clone the repository
git clone https://github.com/Francescolis/Xpandables.Net.gitOpen in Visual Studio 2022 (17.13+) or Rider 2024.3+
Build the solution
dotnet buildRun tests
dotnet test
๐ License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Copyright ยฉ Kamersoft 2025
Licensed under the Apache License, Version 2.0
๐ค Author
Francescolis
- GitHub: @Francescolis
- Company: Kamersoft
๐ฌ Support
If you find this library useful, please consider:
- โญ Starring the repository
- ๐ Reporting issues
- ๐ก Suggesting new features
- ๐ Improving documentation
<div align="center">
Built with โค๏ธ using .NET 10
</div>
| 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
- Microsoft.EntityFrameworkCore (>= 10.0.1)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.1)
- Xpandables.Primitives (>= 10.0.0)
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 |
|---|---|---|
| 10.0.0 | 116 | 1/9/2026 |