OpenCqrs.EventSourcing.Store.EntityFrameworkCore
7.0.0-beta.4
Prefix Reserved
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
<PackageReference Include="OpenCqrs.EventSourcing.Store.EntityFrameworkCore" Version="7.0.0-beta.4" />
<PackageVersion Include="OpenCqrs.EventSourcing.Store.EntityFrameworkCore" Version="7.0.0-beta.4" />
<PackageReference Include="OpenCqrs.EventSourcing.Store.EntityFrameworkCore" />
paket add OpenCqrs.EventSourcing.Store.EntityFrameworkCore --version 7.0.0-beta.4
#r "nuget: OpenCqrs.EventSourcing.Store.EntityFrameworkCore, 7.0.0-beta.4"
#:package OpenCqrs.EventSourcing.Store.EntityFrameworkCore@7.0.0-beta.4
#addin nuget:?package=OpenCqrs.EventSourcing.Store.EntityFrameworkCore&version=7.0.0-beta.4&prerelease
#tool nuget:?package=OpenCqrs.EventSourcing.Store.EntityFrameworkCore&version=7.0.0-beta.4&prerelease
OpenCQRS™
.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 | |
OpenCqrs.EventSourcing | |
OpenCqrs.EventSourcing.Store.EntityFrameworkCore | |
OpenCqrs.EventSourcing.Store.EntityFrameworkCore.Identity |
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
Product | Versions 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. |
-
net9.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.EntityFrameworkCore (>= 9.0.8)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.8)
- OpenCqrs (>= 7.0.0-beta.4)
- OpenCqrs.EventSourcing (>= 7.0.0-beta.4)
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 |