Skip to main content

In-Memory Provider

The In-Memory provider implements IPersistenceProvider for unit testing and local development. It stores data in memory with optional transaction support, allowing tests to run without external database dependencies.

The event store writes each event's declared [MessageName] -- not its CLR type name -- to the stored event-type field, and resolves that name back to a CLR type through the registered event-type registry on read. See Stable Message Names.

Before You Start​

Installation​

dotnet add package Excalibur.Data.InMemory

Dependencies: Excalibur.Data.Abstractions

Quick Start​

using Microsoft.Extensions.DependencyInjection;

// Configure options and register in-memory provider for testing
services.Configure<InMemoryProviderOptions>(options => options.Name = "test");
services.AddSingleton<IPersistenceProvider, InMemoryPersistenceProvider>();

Use Cases​

ScenarioBenefit
Unit testsNo database infrastructure required
Integration testsFast, isolated test execution
Local developmentQuick startup without Docker
CI/CD pipelinesNo external service dependencies

Testing Pattern​

public class OrderServiceTests
{
private readonly IServiceProvider _services;

public OrderServiceTests()
{
var collection = new ServiceCollection();
collection.Configure<InMemoryProviderOptions>(options => options.Name = "test");
collection.AddSingleton<IPersistenceProvider, InMemoryPersistenceProvider>();
collection.AddTransient<OrderService>();
_services = collection.BuildServiceProvider();
}

[Fact]
public async Task CreateOrder_ShouldPersist()
{
var service = _services.GetRequiredService<OrderService>();
var order = await service.CreateOrderAsync(new CreateOrderCommand("item-1"), CancellationToken.None);
order.ShouldNotBeNull();
}
}

Limitations​

  • Data is lost when the process exits
  • No query optimization or indexing
  • Single-process only (no distributed scenarios)
  • Not suitable for performance testing

See Also​