Aquila.Core 1.1.0.6-preview

This is a prerelease version of Aquila.Core.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Aquila.Core --version 1.1.0.6-preview
                    
NuGet\Install-Package Aquila.Core -Version 1.1.0.6-preview
                    
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="Aquila.Core" Version="1.1.0.6-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aquila.Core" Version="1.1.0.6-preview" />
                    
Directory.Packages.props
<PackageReference Include="Aquila.Core" />
                    
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 Aquila.Core --version 1.1.0.6-preview
                    
#r "nuget: Aquila.Core, 1.1.0.6-preview"
                    
#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 Aquila.Core@1.1.0.6-preview
                    
#: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=Aquila.Core&version=1.1.0.6-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Aquila.Core&version=1.1.0.6-preview&prerelease
                    
Install as a Cake Tool

Aquila Framework

Build Status .NET License

Aquila is a high-performance, Cosmos DB native Document Store and Event Sourcing framework for .NET, inspired by MartenDB. Designed from the ground up for modern cloud-native architectures, Aquila enables seamless document persistence, atomic batch mutations, event stream management, live projections, and multi-tenant isolation over Azure Cosmos DB or in-memory test providers.


Key Features

  • 🌌 Cosmos DB Native: Direct connection mode support optimized for Azure Cosmos DB container structure using single-container partitioning (/pk) and hierarchical partition keys via PartitionKeyBuilder.
  • ⚡ 1-RU Point Reads: High-efficiency point reads (LoadAsync<T>) executing direct ReadItemAsync operations requiring ~1 Request Unit.
  • 🔌 Decoupled Storage SPI: Independent document (IDocumentStorageProvider) and event (IEventStorageProvider) storage engines, supported by CosmosStorageProvider (CosmosDocumentStorageProvider & CosmosEventStorageProvider) for cloud persistence and InMemoryStorageProvider for testing.
  • 📜 Event Sourcing: First-class stream append operations (StartStream, Append), expected version concurrency checks, stream fetching (FetchStreamAsync), and aggregate rehydration (AggregateStreamAsync).
  • 🔁 Event Upcasting & Snapshotting: Transparent schema evolution via IEventUpcaster chains, plus ISnapshotStrategy<TAggregate>-driven aggregate snapshots to avoid full-stream replay on rehydration.
  • 📊 Projections: Read-model generation via SingleStreamProjection<TAggregate> and MultiStreamProjection<TDoc,TId>, offering Inline (transaction-scoped), Async (background daemon), and Live (on-the-fly, unpersisted) execution lifecycles.
  • 🛰️ Async Projection Daemon: A background IProjectionDaemon with durable checkpointing, CatchUpAsync(), and zero-downtime RebuildProjectionAsync() — plus a Cosmos DB Change Feed-aware variant (CosmosProjectionDaemon) via AddCosmosDaemon().
  • ✂️ Partial Document Patching: Fluent IPatchExpression<T> API (Set, Increment, Append, Remove) for low-payload mutations that skip full read-modify-write round-trips, executed server-side on Cosmos DB via the Patch API.
  • 🧮 Compiled Queries: ICompiledQuery<TDoc,TResult> with a CompiledQueryCache that compiles each query shape's expression tree once and reuses it across parameter values.
  • 🎛️ Session Tracking Modes: Choose Lightweight, IdentityMap, or DirtyTracking per session to control identity-map caching and automatic JSON-snapshot dirty checking.
  • 🏢 Multi-Tenant Isolation: Tenant scoping enforced natively at session, document envelope, query, and event store levels.
  • 🛡️ Built-in Safety & Performance:
    • Compiled Expression Trees for zero-reflection event instantiation, property copying, ID selector resolution, upcast envelope creation, and compiled-query execution.
    • Automatic document state snapshotting on Store() to prevent post-store object mutations.
    • Sync-over-async thread starvation protection (blocking synchronous queries throw NotSupportedException).

ASP.NET Core Dependency Injection Setup

Register Aquila in your Program.cs or Startup.cs using the fluent AddAquila extension method.

Azure Cosmos DB Provider

using Aquila.Core.Configuration;
using Aquila.Core.Projections;
using Aquila.Cosmos.Extensions;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAquila(options =>
{
    // Configure Cosmos DB storage provider
    options.UseCosmos(
        connectionString: builder.Configuration.GetConnectionString("CosmosDb")!,
        databaseName: "ProductionDB",
        containerName: "AquilaDocuments"
    );

    // Configure document identity and partition key policies
    options.Schema.For<UserAccount>()
        .Identity(u => u.Id)
        .PartitionKey(u => u.Region);

    // Register projections
    options.Projections.Add<UserProfileProjection>(ProjectionLifecycle.Inline);
});

In-Memory Storage Provider (Testing / Local Dev)

builder.Services.AddAquila(options =>
{
    options.UseInMemoryStorage();
    options.DefaultTenantId = "dev-tenant";
});

Quickstart Guide

1. Document CRUD Operations

using Aquila.Core.Abstractions;

public class CustomerService
{
    private readonly IDocumentStore _store;

    public CustomerService(IDocumentStore store)
    {
        _store = store;
    }

    public async Task ManageCustomerAsync()
    {
        // Open a unit-of-work document session
        using var session = _store.OpenSession();

        var customer = new Customer
        {
            Id = Guid.NewGuid().ToString(),
            Name = "Jane Doe",
            Email = "jane@example.com",
            Region = "US-East"
        };

        // Store document (snapshots state immediately)
        session.Store(customer);
        await session.SaveChangesAsync();

        // 1-RU Point Read by Id and Partition Key
        var loaded = await session.LoadAsync<Customer>(customer.Id, partitionKey: "US-East");

        // Query documents asynchronously
        var eastCoastCustomers = await session.QueryAsync<Customer>(
            c => c.Data.Region == "US-East"
        );

        // Soft delete document
        await session.SoftDeleteAsync<Customer>(customer.Id, partitionKey: "US-East");
        await session.SaveChangesAsync();
    }
}

2. Event Sourcing & Aggregate Rehydration

// Define Event Records
public record OrderPlaced(string OrderId, string CustomerId, decimal TotalAmount);
public record ItemAdded(string OrderId, string ItemSku, decimal Price);
public record OrderCompleted(string OrderId, DateTimeOffset CompletedAt);

// Define Aggregate with Apply methods
public class OrderAggregate
{
    public string Id { get; set; } = string.Empty;
    public string CustomerId { get; set; } = string.Empty;
    public decimal Total { get; set; }
    public bool IsCompleted { get; set; }

    public void Apply(OrderPlaced @event)
    {
        Id = @event.OrderId;
        CustomerId = @event.CustomerId;
        Total = @event.TotalAmount;
    }

    public void Apply(ItemAdded @event)
    {
        Total += @event.Price;
    }

    public void Apply(OrderCompleted @event)
    {
        IsCompleted = true;
    }
}

// Start Stream & Rehydrate Aggregate
public async Task ProcessOrderStreamAsync(IDocumentStore store, string orderId)
{
    using var session = store.OpenSession();

    // Start a new event stream
    session.Events.StartStream<OrderAggregate>(orderId,
        new OrderPlaced(orderId, "CUST-100", 99.99m),
        new ItemAdded(orderId, "SKU-ABC", 25.00m)
    );
    await session.SaveChangesAsync();

    // Append subsequent events with concurrency check (expectedVersion)
    session.Events.Append(orderId, expectedVersion: 2, new OrderCompleted(orderId, DateTimeOffset.UtcNow));
    await session.SaveChangesAsync();

    // Rehydrate state by replaying event stream
    var order = await session.Events.AggregateStreamAsync<OrderAggregate>(orderId);
    Console.WriteLine($"Order {order?.Id} Total: ${order?.Total}, Completed: {order?.IsCompleted}");
}

3. Projections

// Define SingleStreamProjection for read-model generation
public class OrderSummaryProjection : SingleStreamProjection<OrderAggregate>
{
    public OrderSummaryProjection()
    {
        CreateEvent<OrderPlaced>(e => new OrderAggregate
        {
            Id = e.OrderId,
            CustomerId = e.CustomerId,
            Total = e.TotalAmount
        });

        ProjectEvent<ItemAdded>((e, agg) => agg.Total += e.Price);
        ProjectEvent<OrderCompleted>((e, agg) => agg.IsCompleted = true);
    }
}

Building & Testing

Prerequisites

Build Solution

dotnet build Aquila.slnx

Run Unit & Integration Tests

dotnet test Aquila.slnx

Documentation

  • 📐 Architecture Guide - Detailed sitemap, SPI storage engine specs, sequence diagrams, and security controls.
  • 📖 Usage & Features Guide - Deep dive into document mapping, soft deletes, optimistic concurrency, event sourcing, projections (single/multi-stream/live/async), the projection daemon, patching, upcasting, snapshotting, compiled queries, session tracking modes, and multi-tenancy.

License

This project is licensed under the MIT License.

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 (2)

Showing the top 2 NuGet packages that depend on Aquila.Core:

Package Downloads
Aquila.Cosmos

Azure Cosmos DB storage engine, Change Feed projection daemon, and point patching implementation for the Aquila Document Store and Event Sourcing framework.

Aquila.Redis

High-performance Redis projection storage provider, document store, and checkpoint persistence for the Aquila Document Store & Event Sourcing Framework.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1.16 166 9/25/2026
1.1.0.15 155 9/2/2026
1.1.0.12-preview 155 8/21/2026
1.1.0.11-preview 127 8/19/2026
1.1.0.10-preview 113 8/18/2026
1.1.0.9-preview 112 8/17/2026
1.1.0.8-preview 115 8/16/2026
1.1.0.7-preview 115 8/16/2026
1.1.0.6-preview 116 8/15/2026
1.1.0.5-preview 114 8/14/2026
1.0.1.4-preview 118 8/13/2026
1.0.0.3-preview 118 8/12/2026