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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xpandables.Entities.Data" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xpandables.Entities.Data" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Xpandables.Entities.Data" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Xpandables.Entities.Data --version 10.0.0
                    
#r "nuget: Xpandables.Entities.Data, 10.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Xpandables.Entities.Data@10.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Xpandables.Entities.Data&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Xpandables.Entities.Data&version=10.0.0
                    
Install as a Cake Tool

<div align="center">

๐Ÿ“ฆ Xpandables.Net

License .NET Version

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 sourcing
  • BankAccounts/Features/CreateBankAccount/ - Complete CQRS command example
  • EventStorage/ - Event store and outbox configuration

๐Ÿ“š Documentation

Package Documentation

Each package has detailed documentation with examples and API references:

Foundation Packages
Application Layer
Data Access
Event Handling
HTTP & REST
  • ๐ŸŒ System.Rests - Type-safe REST client with attribute-based routing
Async & Utilities
ASP.NET Core Integration

๐Ÿ—๏ธ 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

  1. Clone the repository

    git clone https://github.com/Francescolis/Xpandables.Net.git
    
  2. Open in Visual Studio 2022 (17.13+) or Rider 2024.3+

  3. Build the solution

    dotnet build
    
  4. Run 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


๐Ÿ’ฌ 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

โฌ† back to top

</div>

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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