Hexalith.EventStores 1.0.0

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

Hexalith.EventStores Implementation

This package provides the concrete implementation of the Hexalith.EventStores.Abstractions interfaces using a key-value storage backend.

Key Components

KeyValueEventStore

The KeyValueEventStore is the core implementation of the IEventStore interface that provides:

  • Event persistence using a key-value storage mechanism
  • Snapshot management for performance optimization
  • Concurrent access control with session-based locking
  • Thread-safe operations with cancellation support
Key Features
  • Versioned Events: Each event is stored with an incremental version number
  • Session Management: Prevents concurrent access to the same event stream
  • Snapshot Support: Improves read performance by avoiding full event replay
  • Async Operations: Full async/await support with cancellation tokens

KeyValueEventStoreProvider

The KeyValueEventStoreProvider implements the IEventStoreProvider interface and acts as a factory for KeyValueEventStore instances:

  • Creates and manages event store instances
  • Configures the underlying key-value stores for events and snapshots
  • Handles naming and partitioning of event streams

EventState

The EventState record encapsulates the state of an event within the store, containing:

  • The event message with its data and metadata
  • Additional internal state information

Usage Examples

Creating and Using a Store

// Create the store provider with your key-value storage implementation
IKeyValueStorage storage = new YourKeyValueStorage();
IEventStoreProvider provider = new KeyValueEventStoreProvider(storage);

// Get or create a specific event stream
IEventStore store = await provider.GetOrCreateStoreAsync(
    "MyAggregateId",
    CancellationToken.None);

// Open the store with custom timeouts
await store.OpenAsync(
    TimeSpan.FromMinutes(5),   // Session timeout
    TimeSpan.FromSeconds(10),  // Open timeout
    CancellationToken.None);

try
{
    // Add events to the store
    var events = new List<EventMessage> { /* your events */ };
    long version = await store.AddAsync(events, CancellationToken.None);
    
    // Retrieve all events
    IEnumerable<EventMessage> allEvents = await store.GetAsync(CancellationToken.None);
    
    // Create a snapshot
    await store.SnapshotAsync(
        version,
        CalculateSnapshot(allEvents),  // Your snapshot creation logic
        CancellationToken.None);
}
finally
{
    // Always close the store when done
    store.Close();
}

Implementation Details

Storage Structure

The implementation uses three separate key-value stores:

  1. Event Store: Stores individual events with version numbers as keys
  2. Snapshot Store: Stores snapshots with version numbers as keys
  3. Snapshot Collection Store: Tracks available snapshot versions

Concurrency Control

The implementation uses a static concurrent dictionary to track active sessions, with:

  • Session IDs to identify unique access tokens
  • Expiration timestamps to handle session timeouts
  • Lock checking on all operations to ensure exclusive access

Snapshot Management

Snapshots are managed through several methods:

  • SnapshotAsync: Creates a snapshot at a specific version
  • SnapshotAllAsync: Creates snapshots at regular intervals
  • ClearSnapshotAsync: Removes a specific snapshot
  • ClearSnapshotsAsync: Removes all snapshots

Implementation Notes

  • The key-value store implementation is pluggable, allowing for different storage backends
  • The store uses optimistic concurrency by verifying event sequence numbers
  • Resource cleanup is handled through both synchronous and asynchronous disposal
  • All public methods are thread-safe
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

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
1.0.0 90 4/12/2025