Excalibur.Dispatch.Serialization.MemoryPack
3.0.0-alpha.19
dotnet add package Excalibur.Dispatch.Serialization.MemoryPack --version 3.0.0-alpha.19
NuGet\Install-Package Excalibur.Dispatch.Serialization.MemoryPack -Version 3.0.0-alpha.19
<PackageReference Include="Excalibur.Dispatch.Serialization.MemoryPack" Version="3.0.0-alpha.19" />
<PackageVersion Include="Excalibur.Dispatch.Serialization.MemoryPack" Version="3.0.0-alpha.19" />
<PackageReference Include="Excalibur.Dispatch.Serialization.MemoryPack" />
paket add Excalibur.Dispatch.Serialization.MemoryPack --version 3.0.0-alpha.19
#r "nuget: Excalibur.Dispatch.Serialization.MemoryPack, 3.0.0-alpha.19"
#:package Excalibur.Dispatch.Serialization.MemoryPack@3.0.0-alpha.19
#addin nuget:?package=Excalibur.Dispatch.Serialization.MemoryPack&version=3.0.0-alpha.19&prerelease
#tool nuget:?package=Excalibur.Dispatch.Serialization.MemoryPack&version=3.0.0-alpha.19&prerelease
Excalibur.Dispatch.Serialization.MemoryPack
High-performance MemoryPack binary serialization for Excalibur framework.
Purpose
Provides the default and fastest binary serialization for:
- Internal persistence (Outbox, Inbox, Event Store)
- Maximum throughput scenarios
- .NET-to-.NET communication
- AOT/NativeAOT deployment
Key Features
- Auto-Registered: Enabled by default when using
AddDispatch() - Serializer ID 1: Magic byte
0x01in persisted payloads - Zero-Allocation: ReadOnlySpan-based deserialization
- AOT-Compatible: Full NativeAOT and trimming support
Usage
Default (Zero Configuration)
MemoryPack is automatically registered and used as the default serializer:
services.AddDispatch();
// That's it! MemoryPack is auto-registered and set as current.
Explicit Registration
For clarity or migration scenarios:
services.AddDispatch()
.ConfigurePluggableSerialization(config =>
{
config.RegisterMemoryPack(); // Register (ID: 1)
config.UseMemoryPack(); // Set as current
});
Disable Auto-Registration
When you want explicit control:
services.AddDispatch()
.ConfigurePluggableSerialization(config =>
{
config.DisableMemoryPackAutoRegistration();
config.RegisterSystemTextJson();
config.UseSystemTextJson();
});
Type Requirements
Types must have the [MemoryPackable] attribute:
[MemoryPackable]
public partial class UserCreatedEvent
{
public string UserId { get; set; }
public string Name { get; set; }
public DateTime CreatedAt { get; set; }
}
Important: The partial keyword is required for source generation.
Constructor Parameters
For immutable types:
[MemoryPackable]
public partial class OrderPlacedEvent
{
[MemoryPackConstructor]
public OrderPlacedEvent(string orderId, decimal total)
{
OrderId = orderId;
Total = total;
}
public string OrderId { get; }
public decimal Total { get; }
}
Performance Characteristics
| Metric | Value | Notes |
|---|---|---|
| Serialization | ~150ns/1KB | Fastest .NET binary format |
| Deserialization | ~120ns/1KB | Zero-allocation span slicing |
| Payload Size | Smallest | Optimal binary encoding |
| Memory Pressure | Minimal | No GC allocations in hot path |
Pluggable Serialization Integration
MemoryPack is assigned Serializer ID 1 in the pluggable serialization system.
The magic byte 0x01 prefixes all MemoryPack-serialized payloads.
Stored Payload: [0x01][MemoryPack binary data...]
^
Magic byte identifies serializer
When to Use MemoryPack (Default)
Best For:
- Internal .NET-to-.NET communication
- Maximum performance requirements
- Event sourcing and Outbox persistence
- AOT/NativeAOT deployments
Consider Alternatives When:
- Cross-language consumers (use MessagePack - ID: 3)
- Debugging/human-readable storage (use System.Text.Json - ID: 2)
- Schema-based contracts (use Protobuf - ID: 4)
Migration
From MemoryPack to Another Serializer
services.AddDispatch()
.ConfigurePluggableSerialization(config =>
{
// MemoryPack (ID: 1) auto-registered - keep for existing data
config.RegisterMessagePack(); // Add new serializer
config.UseMessagePack(); // Use for new messages
});
Old MemoryPack data remains readable; new data uses MessagePack.
To MemoryPack from Another Serializer
services.AddDispatch()
.ConfigurePluggableSerialization(config =>
{
config.RegisterSystemTextJson(); // Keep for existing data
config.UseMemoryPack(); // Switch to MemoryPack
});
Package Dependencies
MemoryPack- Core MemoryPack serialization runtimeExcalibur.Dispatch.Abstractions- Core contracts
AOT Compatibility
Full NativeAOT support with source-generated serializers.
Ensure all serializable types have [MemoryPackable] attribute with partial class declaration.
See Also
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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 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
- Excalibur.Dispatch.Abstractions (>= 3.0.0-alpha.19)
- Medo.Uuid7 (>= 1.4.0)
- MemoryPack (>= 1.21.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
-
net8.0
- Excalibur.Dispatch.Abstractions (>= 3.0.0-alpha.19)
- Medo.Uuid7 (>= 1.4.0)
- MemoryPack (>= 1.21.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- System.Diagnostics.DiagnosticSource (>= 10.0.0)
-
net9.0
- Excalibur.Dispatch.Abstractions (>= 3.0.0-alpha.19)
- Medo.Uuid7 (>= 1.4.0)
- MemoryPack (>= 1.21.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- System.Diagnostics.DiagnosticSource (>= 10.0.0)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Excalibur.Dispatch.Serialization.MemoryPack:
| Package | Downloads |
|---|---|
|
Excalibur.Dispatch
Core messaging abstractions and middleware pipeline for the Excalibur framework. Provides foundational types for message handling, routing, and extensible middleware architecture. |
|
|
Excalibur.Data.Postgres
Postgres database provider implementation for Excalibur data access layer. |
|
|
Excalibur.EventSourcing.Postgres
Postgres implementations for Excalibur event sourcing, including event store, snapshot store, and outbox store. |
|
|
Excalibur.EventSourcing.SqlServer
SQL Server implementations for Excalibur event sourcing, including event store, snapshot store, and outbox store. |
|
|
Excalibur.Data.MongoDB
MongoDB database provider implementation for Excalibur data access layer. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0-alpha.19 | 76 | 2/26/2026 |