Skip to content
Purview Dev logo

Event Sourcing

Preview

Aggregate-based event sourcing for .NET across any store.

aggregates azure-cosmosdb azure-storage cqrs csharp ddd dotnet event-driven event-sourcing event-store mongodb postgresql roslyn snapshots source-generator sql-server transactions

The problem

A .NET event sourcing framework for building aggregate-based applications. Provider-agnostic store facades, source-generated aggregates and events, transaction coordination for multi-aggregate saves, queryable snapshots and read models, and storage providers for SQL Server, PostgreSQL, MongoDB, Azure Storage, Azure Cosmos DB, and in-memory.

From the repository

A .NET event sourcing framework for building aggregate-based applications - provider-agnostic store facades, source-generated aggregates, transaction coordination, queryable snapshots and read models, and storage providers for SQL Server, PostgreSQL, MongoDB, Azure Storage, Azure Cosmos DB, and in-memory.

Why it became a project

Aggregate, event, persistence, and transaction patterns kept recurring across applications, so the reusable parts were separated from any one storage provider.

Where it fits

Use it when

Your domain benefits from aggregate-based event sourcing and you want storage choices, snapshots, read models, and transactions behind consistent abstractions.

It may not fit when

A conventional state-based model is sufficient, or your application does not need the operational and modelling trade-offs that come with event sourcing.

Use cases

Concrete examples of what Event Sourcing does, and who each one is for.

Developer

An aggregate that persists as events

You want aggregate-based event sourcing without hand-writing the event stream, snapshot, and transaction plumbing.

csharp
[Aggregate]
public partial class OrderAggregate : AggregateBase
{
    public string CustomerId { get; private set; } = default!;
    public decimal Total { get; private set; }

    [Event]
    public partial void CreateOrder(string customerId);

    [Event]
    public partial void AddLineItem(string productId, string productName, int quantity, decimal unitPrice);
}

What you get: The source generator produces the aggregate plumbing; provider packages add stores for SQL Server, PostgreSQL, MongoDB, Azure Storage, Cosmos DB, or in-memory.

One [Aggregate] declaration, and switching storage means swapping a provider package rather than rewriting the domain.

Read the guide →
Architect

Choose the store late, keep the domain stable

You need to start on one database and move providers later, but you do not want persistence choices to leak into the domain model.

csharp
builder.Services.AddSqlServerEventStore();
builder.Services.AddSqlServerSnapshotQueryableEventStore();

What you get: Domain code depends on provider-agnostic facades, while concrete stores live behind separate packages and registration extensions.

SQL Server, PostgreSQL, MongoDB, Azure Storage, and Cosmos DB are interchangeable at the registration level, so the domain never references a store.

Read the guide →

Packages

9 packages

Purview.EventSourcingInstall ↓1.1.12.0.0-prerelease.39—
Purview.EventSourcing.AzureStorageInstall ↓1.1.12.0.0-prerelease.39—
Purview.EventSourcing.CosmosDbInstall ↓1.1.12.0.0-prerelease.39—
Purview.EventSourcing.InMemoryInstall ↓1.1.12.0.0-prerelease.39—
Purview.EventSourcing.MongoDBInstall ↓1.1.12.0.0-prerelease.39—
Purview.EventSourcing.PostgresInstall ↓1.1.12.0.0-prerelease.39—
Purview.EventSourcing.SqlServerInstall ↓1.1.12.0.0-prerelease.39—
Purview.EventSourcing.Validation.FluentValidationInstall ↓1.1.12.0.0-prerelease.39—
Purview.EventSourcing.Validation.ZodSharpInstall ↓1.1.12.0.0-prerelease.39—

Install

Purview.EventSourcing primary

.NET CLI
dotnet add package Purview.EventSourcing

Purview.EventSourcing.SqlServer

.NET CLI
dotnet add package Purview.EventSourcing.SqlServer

Purview.EventSourcing.Postgres

.NET CLI
dotnet add package Purview.EventSourcing.Postgres

Purview.EventSourcing.AzureStorage

.NET CLI
dotnet add package Purview.EventSourcing.AzureStorage

Purview.EventSourcing.MongoDB

.NET CLI
dotnet add package Purview.EventSourcing.MongoDB

Purview.EventSourcing.CosmosDb

.NET CLI
dotnet add package Purview.EventSourcing.CosmosDb

Purview.EventSourcing.InMemory

.NET CLI
dotnet add package Purview.EventSourcing.InMemory

Purview.EventSourcing.Validation.FluentValidation

.NET CLI
dotnet add package Purview.EventSourcing.Validation.FluentValidation

Purview.EventSourcing.Validation.ZodSharp

.NET CLI
dotnet add package Purview.EventSourcing.Validation.ZodSharp