CqrsLite 1.36.1

dotnet add package CqrsLite --version 1.36.1
                    
NuGet\Install-Package CqrsLite -Version 1.36.1
                    
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="CqrsLite" Version="1.36.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CqrsLite" Version="1.36.1" />
                    
Directory.Packages.props
<PackageReference Include="CqrsLite" />
                    
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 CqrsLite --version 1.36.1
                    
#r "nuget: CqrsLite, 1.36.1"
                    
#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 CqrsLite@1.36.1
                    
#: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=CqrsLite&version=1.36.1
                    
Install as a Cake Addin
#tool nuget:?package=CqrsLite&version=1.36.1
                    
Install as a Cake Tool

CQRSlite

Build NuGet

A lightweight CQRS and Event Sourcing framework for .NET

Overview

CQRSlite is a small, focused CQRS (Command Query Responsibility Segregation) and Event Sourcing framework for .NET. It provides the essential building blocks for implementing CQRS/ES patterns while maintaining flexibility and pluggability.

Key Characteristics:

  • Minimal dependencies (only Microsoft.Extensions.Caching.Memory)
  • Targets netstandard2.0 and net10.0
  • Convention-based event application with performance optimization
  • Pluggable architecture - replace any component with custom implementations
  • Thread-safe caching and repository decorators

CQRSlite originated as a CQRS sample project by Greg Young and Gaute Magnussen in 2010. Original code: http://github.com/gregoryyoung/m-r

Features

  • Command Sending - Dispatch commands to handlers with 1:1 routing
  • Event Publishing - Publish events to multiple handlers (1:N routing)
  • Query Processing - Process queries with typed results
  • Unit of Work - Session-based aggregate tracking for consistency
  • Repository Pattern - Get and save aggregates with event sourcing
  • Optimistic Concurrency - Built-in concurrency checking and conflict detection
  • Message Router - Automatic handler registration via reflection
  • Snapshotting - Performance optimization for aggregates with many events
  • Caching - Thread-safe caching layer with automatic invalidation

Quick Start

Installation

dotnet add package CQRSlite

Basic Usage

  1. Define your messages:
// Command
public class CreateProduct : ICommand
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}

// Event
public class ProductCreated : IEvent
{
    public Guid Id { get; set; }
    public int Version { get; set; }
    public DateTimeOffset TimeStamp { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
}
  1. Create your aggregate:
public class Product : AggregateRoot
{
    private string _name;
    private decimal _price;

    public Product(Guid id, string name, decimal price)
    {
        Id = id;
        ApplyChange(new ProductCreated(id, name, price));
    }

    private Product() { } // Required for rehydration

    private void Apply(ProductCreated e)
    {
        _name = e.Name;
        _price = e.Price;
    }
}
  1. Implement handlers:
public class ProductCommandHandler : ICommandHandler<CreateProduct>
{
    private readonly ISession _session;

    public async Task Handle(CreateProduct message)
    {
        var product = new Product(message.Id, message.Name, message.Price);
        await _session.Add(product);
        await _session.Commit();
    }
}
  1. Configure services:
// Register Router
var router = new Router();
services.AddSingleton(router);
services.AddSingleton<ICommandSender>(router);
services.AddSingleton<IEventPublisher>(router);
services.AddSingleton<IHandlerRegistrar>(router);

// Register core services
services.AddSingleton<IEventStore, YourEventStore>(); // You must implement this
services.AddScoped<IRepository>(sp => new Repository(sp.GetService<IEventStore>()));
services.AddScoped<ISession, Session>();

// Auto-register handlers
var registrar = new RouteRegistrar(serviceProvider);
registrar.Register(typeof(ProductCommandHandler).Assembly);

Documentation

  • Developer Documentation - Comprehensive guide covering architecture, implementation patterns, best practices, and testing
  • API Reference - Complete API documentation for all interfaces and classes
  • Sample Project - Working example demonstrating common usage patterns

External Resources

Great introductions to CQRS and CQRSlite:

Requirements

You must implement your own IEventStore for persistence. CQRSlite provides the framework but intentionally does not include a default event store implementation, as storage requirements vary greatly between applications.

Example event stores:

  • SQL Server / PostgreSQL / MySQL
  • NoSQL databases (MongoDB, CosmosDB)
  • Event Store DB
  • Azure Table Storage
  • In-memory (for testing, included in sample)

See DEVELOPER.md for implementation guidance.

Architecture

CQRSlite follows clean CQRS/ES principles:

Application Layer
    ↓
Commands → CommandHandlers → Aggregates → Events → EventStore
    ↓                                          ↓
Queries → QueryHandlers → ReadModels ← EventHandlers

Write Side (Commands):

  • Commands express intent to change state
  • Aggregates enforce business rules
  • Events record what happened
  • Event store persists events

Read Side (Queries):

  • Events update denormalized read models
  • Queries read from optimized projections
  • Eventually consistent with write side

Contributing

Contributions are welcome! Please see DEVELOPER.md for guidelines.

Version Compatibility

  • netstandard2.0 - Compatible with .NET Framework 4.6.1+ and .NET Core 2.0+
  • net10.0 - Latest .NET features and performance improvements

License

Copyright 2020 Gaute Magnussen

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (24)

Showing the top 5 NuGet packages that depend on CqrsLite:

Package Downloads
Evelyn.Core

Core functionality for Evelyn

Evelyn.Management.Api.Rest

REST API for the Evelyn Server

Evelyn.Storage.EventStore

An EventStore.org adapter for Evelyn

Neurul.Cortex.Common

neurUL Cortex Common

Neurul.Common.Test

neurUL Common Test

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on CqrsLite:

Repository Stars
exceptionnotfound/DotNetCqrsDemo
Version Downloads Last Updated
1.36.1 132 10/5/2026
1.36.0 89 10/5/2026
1.35.1 30,490 7/23/2025
1.35.0 209,278 4/8/2022
1.34.0 40,689 11/9/2021
1.33.0 70,100 11/11/2020
1.32.2 4,880 7/24/2020
1.32.1 3,139 6/25/2020
1.32.0 22,168 6/9/2020
1.31.1 6,520 4/10/2020
1.31.0 4,081 3/16/2020
1.30.1 1,886 2/21/2020
1.30.0 2,268 2/20/2020
0.29.0 19,250 7/17/2019
0.28.0 4,037 5/6/2019
0.27.0 9,084 1/17/2019
0.26.0 25,325 11/12/2018
0.25.0 17,709 9/20/2018
0.24.0 2,906 8/29/2018
0.23.0 24,736 5/14/2018
Loading failed