OpenCqrs.EventSourcing.Store.EntityFrameworkCore 7.0.0-beta.4

Prefix Reserved
This is a prerelease version of OpenCqrs.EventSourcing.Store.EntityFrameworkCore.
dotnet add package OpenCqrs.EventSourcing.Store.EntityFrameworkCore --version 7.0.0-beta.4
                    
NuGet\Install-Package OpenCqrs.EventSourcing.Store.EntityFrameworkCore -Version 7.0.0-beta.4
                    
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.Store.EntityFrameworkCore" Version="7.0.0-beta.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenCqrs.EventSourcing.Store.EntityFrameworkCore" Version="7.0.0-beta.4" />
                    
Directory.Packages.props
<PackageReference Include="OpenCqrs.EventSourcing.Store.EntityFrameworkCore" />
                    
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.Store.EntityFrameworkCore --version 7.0.0-beta.4
                    
#r "nuget: OpenCqrs.EventSourcing.Store.EntityFrameworkCore, 7.0.0-beta.4"
                    
#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.Store.EntityFrameworkCore@7.0.0-beta.4
                    
#: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.Store.EntityFrameworkCore&version=7.0.0-beta.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=OpenCqrs.EventSourcing.Store.EntityFrameworkCore&version=7.0.0-beta.4&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 Entity Framework Core with any relational database providers (work for a separate Cosmos DB provider is underway).

All features from OpenCQRS 6.x are being added to OpenCQRS 7 beta versions.

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

Packages

Package Beta 4
OpenCqrs Nuget Package
OpenCqrs.EventSourcing Nuget Package
OpenCqrs.EventSourcing.Store.EntityFrameworkCore Nuget Package
OpenCqrs.EventSourcing.Store.EntityFrameworkCore.Identity 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 with Entity Framework Core

All features are implemented as extension methods on the DbContext, allowing seamless integration with your existing DbContext implementations. 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);

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

Event Sourcing with Cosmos DB

Work in progress

Roadmap

OpenCQRS 7.0.0

  • Caching queries with Memory/Redis
  • Message bus integration with Azure Service Bus/RabbitMQ
  • Event Sourcing with Cosmos DB

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

Showing the top 1 NuGet packages that depend on OpenCqrs.EventSourcing.Store.EntityFrameworkCore:

Package Downloads
OpenCqrs.EventSourcing.Store.EntityFrameworkCore.Identity

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.4 0 8/29/2025
7.0.0-beta.3 22 8/26/2025
7.0.0-beta.2 37 8/26/2025
7.0.0-beta.1 48 8/25/2025