Cosmos.EventSourcing.CritterStack
0.1.7
dotnet add package Cosmos.EventSourcing.CritterStack --version 0.1.7
NuGet\Install-Package Cosmos.EventSourcing.CritterStack -Version 0.1.7
<PackageReference Include="Cosmos.EventSourcing.CritterStack" Version="0.1.7" />
<PackageVersion Include="Cosmos.EventSourcing.CritterStack" Version="0.1.7" />
<PackageReference Include="Cosmos.EventSourcing.CritterStack" />
paket add Cosmos.EventSourcing.CritterStack --version 0.1.7
#r "nuget: Cosmos.EventSourcing.CritterStack, 0.1.7"
#:package Cosmos.EventSourcing.CritterStack@0.1.7
#addin nuget:?package=Cosmos.EventSourcing.CritterStack&version=0.1.7
#tool nuget:?package=Cosmos.EventSourcing.CritterStack&version=0.1.7
Cosmos.EventSourcing.CritterStack
Implementación completa de Event Sourcing y CQRS usando Wolverine y Marten (CritterStack).
Descripción
Este paquete proporciona implementaciones listas para producción de todas las abstracciones definidas en Cosmos.EventSourcing.Abstractions. Utiliza Wolverine para mensajería y mediación, y Marten como Event Store y Document Database sobre PostgreSQL.
CritterStack es el nombre de la combinación de Wolverine + Marten, dos poderosas herramientas del ecosistema .NET.
Características
Event Store
- MartenEventStore: Implementación de
IEventStoreusando Marten - Soporte para recuperar agregados por ID, versión o timestamp
- Soporte para verificar existencia de agregados con
ExistsAsync<T> - Persistencia de eventos en PostgreSQL
Command Routing
- WolverineCommandRouter: Router de comandos usando Wolverine
- Soporte para comandos con y sin valor de retorno
- Integración con multi-tenancy
Query Routing
- WolverineQueryRouter: Router de consultas usando Wolverine
- Ejecución distribuida de queries
Projection Store
- MartenProjectionStore: Almacén de proyecciones usando Marten
- Operaciones CRUD sobre proyecciones/vistas de lectura
Instalación
dotnet add package Cosmos.EventSourcing.CritterStack
Este paquete incluye automáticamente las dependencias de:
- Cosmos.EventSourcing.Abstractions
- Cosmos.MultiTenancy
Configuración
Registrar Servicios (con IHostBuilder)
using Cosmos.EventSourcing.CritterStack;
var builder = WebApplication.CreateBuilder(args);
// Configura Wolverine + Marten para comandos
builder.Host.UsarWolverineParaComandos(
dominioAssembly: typeof(MiAgregado).Assembly,
martenConnectionString: builder.Configuration.GetConnectionString("Postgres")!,
databaseSchemaName: "mi_servicio",
isDevelopment: builder.Environment.IsDevelopment()
);
// Registra el router de comandos
builder.Services.AgregarWolverineCommandRouter();
// Registra el router de consultas
builder.Services.AgregarWolverineQueryRouter();
var app = builder.Build();
app.Run();
Configuración Serverless (Azure Functions)
// Para entornos serverless usa AgregarWolverineParaComandosServerless
builder.Services.AgregarWolverineParaComandosServerless(
dominioAssembly: typeof(MiAgregado).Assembly,
martenConnectionString: connectionString,
databaseSchemaName: "mi_servicio",
isDevelopment: false
);
Uso
Implementar Command Handlers con Wolverine
using Cosmos.EventSourcing.Abstractions.Commands;
public record CreateOrder(string OrderId, string CustomerId);
// Los handlers son descubiertos automáticamente por Wolverine
public class CreateOrderHandler
{
private readonly IEventStore _eventStore;
public CreateOrderHandler(IEventStore eventStore)
{
_eventStore = eventStore;
}
public async Task Handle(CreateOrder command, CancellationToken ct)
{
var order = new Order(command.OrderId, command.CustomerId);
_eventStore.Save(order);
await _eventStore.SaveChangesAsync();
}
}
Ejecutar Comandos con el Router
public class OrderController : ControllerBase
{
private readonly ICommandRouter _commandRouter;
public OrderController(ICommandRouter commandRouter)
{
_commandRouter = commandRouter;
}
[HttpPost]
public async Task<IActionResult> CreateOrder(CreateOrderRequest request)
{
var command = new CreateOrder(Guid.NewGuid().ToString(), request.CustomerId);
await _commandRouter.InvokeAsync(command, HttpContext.RequestAborted);
return Ok(new { OrderId = command.OrderId });
}
}
Implementar Query Handlers
public record GetOrderById(string OrderId);
public class GetOrderByIdHandler
{
private readonly IProjectionStore _projectionStore;
public GetOrderByIdHandler(IProjectionStore projectionStore)
{
_projectionStore = projectionStore;
}
public async Task<OrderDto?> Handle(GetOrderById query, CancellationToken ct)
{
return await _projectionStore.GetByIdAsync<OrderDto>(query.OrderId, ct);
}
}
Trabajar con Proyecciones
using Cosmos.EventSourcing.Linq.Extensions;
public class OrderQueryService
{
private readonly IQuerySession _querySession;
public OrderQueryService(IQuerySession querySession)
{
_querySession = querySession;
}
public async Task<IReadOnlyList<OrderDto>> GetCustomerOrdersAsync(
string customerId,
CancellationToken ct)
{
var orders = await _querySession
.Query<OrderDto>()
.Where(o => o.CustomerId == customerId)
.OrderByDescending(o => o.CreatedAt)
.ToListAsync(ct);
return orders;
}
}
Multi-Tenancy
Este paquete incluye soporte para multi-tenancy a través de Cosmos.MultiTenancy. Los routers de comandos y queries utilizan automáticamente el TenantResolver para ejecutar operaciones en el contexto del tenant correcto:
// El WolverineCommandRouter usa automáticamente el TenantId
await _commandRouter.InvokeAsync(command, ct);
// Internamente: messageBus.InvokeForTenantAsync(tenantId, command, ct)
Requisitos
- .NET 10.0 o superior
- PostgreSQL 12+ (para Marten)
Dependencias
- Marten (v8.23.0) - Event Store y Document DB
- WolverineFx.Marten (v5.18.0) - Integración Wolverine-Marten
- Cosmos.EventSourcing.Abstractions
- Cosmos.MultiTenancy
Recursos
Licencia
Copyright © Cosmos. Todos los derechos reservados.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- Marten (>= 8.23.0)
- WolverineFx.Marten (>= 5.18.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.7 | 69 | 3/12/2026 |
| 0.1.6 | 43 | 3/12/2026 |
| 0.1.5 | 35 | 3/12/2026 |
| 0.1.5-RC.1 | 75 | 3/10/2026 |
| 0.1.4 | 150 | 2/24/2026 |
| 0.1.3 | 164 | 2/23/2026 |
| 0.1.2 | 115 | 2/11/2026 |
| 0.1.1 | 97 | 2/11/2026 |
| 0.1.0 | 97 | 2/10/2026 |
| 0.0.8 | 94 | 2/9/2026 |
| 0.0.7 | 679 | 12/3/2025 |
| 0.0.6 | 683 | 12/3/2025 |
| 0.0.5 | 213 | 11/25/2025 |
| 0.0.1 | 305 | 9/19/2025 |