OpenCqrs.EventSourcing 7.0.0-beta.5

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

OpenCQRS™

.Build

.NET framework implementing DDD, Event Sourcing, and CQRS. OpenCQRS 7 is a revamped version of the project with a complete rewrite of the codebase.

OpenCQRS 7 is extremely flexible and expandable. It can be used as a simple mediator or as a full Event Sourcing solution with Cosmos DB or Entity Framework Core with any relational database providers.

Note: OpenCQRS was made private when it had 681 stars and made public again in preparation of version 7.

Packages

Package Beta 5
OpenCqrs Nuget Package
OpenCqrs.EventSourcing Nuget Package
OpenCqrs.EventSourcing.Store.Cosmos Nuget Package
OpenCqrs.EventSourcing.Store.EntityFrameworkCore Nuget Package
OpenCqrs.EventSourcing.Store.EntityFrameworkCore.Identity Nuget Package
OpenCqrs.Validation.FluentValidation Nuget Package

Simple mediator

Three kinds of requests can be sent through the dispatcher:

Commands

public class DoSomething : ICommand
{
}

public class DoSomethingHandler : ICommandHandler<DoSomething>
{
    private readonly IMyService _myService;

    public DoSomethingHandler(IMyService myService)
    {
        _myService = myService;
    }

    public async Task<Result> Handle(DoSomething command)
    {
        await _myService.MyMethod();

        return Result.Ok();
    }
}

await _dispatcher.Send(new DoSomething());

Queries

public class Something
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class GetSomething : IQuery<Something>
{
    public int Id { get; set; }
}

public class GetSomethingQueryHandler : IQueryHandler<GetSomething, Something>
{
    private readonly MyDbContext _dbContext;

    public GetProductsHandler(MyDbContext dbContext)
    {
        _dbContext = dbContext;
    }
        
    public Task<Result<Something>> Handle(GetSomething query)
    {
        return _dbContext.Somethings.FirstOrDefaultAsync(s => s.Id == query.Id);
    }
}

var something = await _dispatcher.Get(new GetSomething { Id = 123 });

Notifications

public class SomethingHappened : INotifcation
{
}

public class SomethingHappenedHandlerOne : INotifcationHandler<SomethingHappened>
{
    private readonly IServiceOne _serviceOne;

    public SomethingHappenedHandlerOne(IServiceOne serviceOne)
    {
        _serviceOne = serviceOne;
    }

    public Task<Result> Handle(SomethingHappened notification)
    {
        return _serviceOne.DoSomethingElse();
    }
}

public class SomethingHappenedHandlerTwo : INotifcationHandler<SomethingHappened>
{
    private readonly IServiceTwo _serviceTwo;

    public SomethingHappenedHandlerTwo(IServiceTwo serviceTwo)
    {
        _serviceTwo = serviceTwo;
    }

    public Task<Result> Handle(SomethingHappened notification)
    {
        return _serviceTwo.DoSomethingElse();
    }
}

await _dispatcher.Publish(new SomethingHappened());

Event Sourcing

You can use the IDomainService interface to access the event-sourcing functionalities for every store provider.

In the Cosmos DB store provider you can also use the ICosmosDataStore interface to access Cosmos DB specific features.

In the Entity Framework Core store provider you can also use the IDomainDbContext extensions to access Entity Framework Core specific features. In the Entity Framework Core store provider, IdentityDbContext from ASP.NET Core Identity is also supported.

[AggregateType("Order")]
puclic class OrderAggregate : Aggregate
{
    public override Type[] EventTypeFilter { get; } =
    [
        typeof(OrderPlaced) // Only events of this type will be loaded for the aggregate from the event stream
    ];
        
    public Guid OrderId { get; private set; }
    public decimal Amount { get; private set; }

    public Order() { }

    public Order(Guid orderId, decimal amount)
    {
        Add(new OrderPlaced
        {
            OrderId = orderId,
            Amount = amount
        };);
    }

    protected override bool Apply<TDomainEvent>(TDomainEvent domainEvent)
    {
        return domainEvent switch
        {
            OrderPlaced @event => Apply(@event)
            _ => false
        };
    }

    private bool Apply(OrderPlaced @event)
    {
        OrderId = @event.OrderId;
        Amount = @event.Amount;

        return true;
    }
}

var streamId = new CustomerStreamId(customerId);
var aggregateId = new OrderAggregateId(orderId);
var aggregate = new OrderAggregate(orderId, amount: 25.45m);

// Save aggregate method stores the new events and the snapshot of the aggregate to the latest state
var result = await domainService.SaveAggregate(streamId, aggregateId, aggregate, expectedEventSequence: 0);

Roadmap

OpenCQRS 7.0.0

  • All features from OpenCQRS 6.x
  • Complete rewrite of the framework
  • Upgrade to .NET 9
  • New mediator pattern with commands, queries, and notifications
  • Cosmos DB store provider
  • Entity Framework Core store provider
  • Extensions for db context in the Entity Framework Core store provider
  • Support for IdentityDbContext from ASP.NET Core Identity
  • Command validation
  • Command sequences
  • Send and publish methods that automatically publish notifications on the back of a successfully processed command
  • More flexible and extensible architecture
  • Better performance
  • Better test coverage
  • More documentation and examples

OpenCQRS 7.1.0

  • More extensions for domain events and event entities in the Entity Framework Core store provider
  • Get domain events and event entities as IAsyncEnumerable in the Entity Framework Core store provider
  • Custom table names for EntityFrameworkCore store provider
  • Custom handlers/services per command/query/notification

Full Documentation

Legacy documentation here (OpenCQRS 6.x)

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 was computed.  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 OpenCqrs.EventSourcing:

Package Downloads
OpenCqrs.EventSourcing.Store.EntityFrameworkCore

Open source CQRS and Event Sourcing framework for .NET.

OpenCqrs.EventSourcing.Store.Cosmos

Open source CQRS and Event Sourcing framework for .NET.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.0.0-beta.5 36 9/1/2025
7.0.0-beta.4 147 8/29/2025
7.0.0-beta.3 180 8/26/2025
7.0.0-beta.2 172 8/26/2025
7.0.0-beta.1 105 8/25/2025