Tyto.Materializer
0.0.1-alpha.47
dotnet add package Tyto.Materializer --version 0.0.1-alpha.47
NuGet\Install-Package Tyto.Materializer -Version 0.0.1-alpha.47
<PackageReference Include="Tyto.Materializer" Version="0.0.1-alpha.47" />
<PackageVersion Include="Tyto.Materializer" Version="0.0.1-alpha.47" />
<PackageReference Include="Tyto.Materializer" />
paket add Tyto.Materializer --version 0.0.1-alpha.47
#r "nuget: Tyto.Materializer, 0.0.1-alpha.47"
#:package Tyto.Materializer@0.0.1-alpha.47
#addin nuget:?package=Tyto.Materializer&version=0.0.1-alpha.47&prerelease
#tool nuget:?package=Tyto.Materializer&version=0.0.1-alpha.47&prerelease
Tyto.Materializer
A high-performance, resilient projection engine for building Materialized Views in Event-Driven Architectures and CQRS systems.
Tyto.Materializer transforms a stream of domain events into query-optimized read models (Views). Unlike standard caching mechanisms (Last-Write-Wins), it enforces strong data consistency using optimistic concurrency control, ensuring your read models never get overwritten by stale data, even under high concurrency.
🚀 Key Features
- Event-Driven & Reactive: Seamlessly integrates with message buses to update views in near real-time.
- Optimistic Concurrency: Uses Version Vectors to handle race conditions automatically.
- Class-Based Projectors: Cleanly separate your projection logic into testable classes (
IViewProjector) with full Dependency Injection support. - Auto-Discovery: Automatically registers all projection rules implemented by a class using Reflection, keeping your startup configuration clean.
- Resilient: Built-in retry policies with exponential backoff for handling concurrency conflicts.
- Storage Agnostic: Plug-and-play storage providers (Redis, EF Core, InMemory).
📦 Installation
dotnet add package Tyto.Materializer
> Note: You will likely need a storage provider package as well, such as Tyto.Materializer.Redis.
⚡ Getting Started
1. Define Your View
Views are simple POCO classes that implement IProjectableView. This interface adds a Version property which the library uses to track state changes and prevent race conditions.
using Tyto.Materializer;
public class UserBalanceView : IProjectableView
{
// The unique key for this view (e.g., UserId)
public Guid UserId { get; set; }
public string FullName { get; set; } = string.Empty;
public decimal CurrentBalance { get; set; }
public DateTime LastUpdated { get; set; }
// Managed automatically by Tyto
public ProjectableVersion Version { get; set; }
}
2. Define a Projector
Instead of writing logic inside configuration files, define your projection logic in clean, testable classes implementing IViewProjector<TView, TEvent>. You can inject repositories, loggers, or other services here.
using Tyto.Materializer;
public class UserBalanceProjector :
IViewProjector<UserBalanceView, UserRegistered>,
IViewProjector<UserBalanceView, MoneyDeposited>
{
private readonly ILogger<UserBalanceProjector> _logger;
public UserBalanceProjector(ILogger<UserBalanceProjector> logger)
{
_logger = logger;
}
public ValueTask ProjectAsync(UserBalanceView view, UserRegistered @event, CancellationToken ct)
{
// Tyto automatically handles creating the view instance if it doesn't exist.
view.UserId = @event.UserId;
view.FullName = @event.Name;
view.CurrentBalance = 0;
view.LastUpdated = DateTime.UtcNow;
_logger.LogInformation("Projection created for user {Id}", @event.UserId);
return ValueTask.CompletedTask;
}
public ValueTask ProjectAsync(UserBalanceView view, MoneyDeposited @event, CancellationToken ct)
{
view.CurrentBalance += @event.Amount;
view.LastUpdated = DateTime.UtcNow;
return ValueTask.CompletedTask;
}
}
3. Configure in Program.cs
Wire everything up using the Fluent API.
builder.Services.AddTytoConfiguration(tyto =>
{
tyto.AddMaterializer(materializer =>
{
materializer.ForView<UserBalanceView>()
// 1. Identify the Key: How to extract the View ID from an Event
.IdentifiedAs<Guid>(id => id.From<UserRegistered>(e => e.UserId))
// 2. Configure Storage: Choose where to save the view
.Store.UseRedis("localhost:6379,abortConnect=false")
// 3. Register Projectors: Use the class-based approach
// This single line automatically registers BOTH UserRegistered and MoneyDeposited
// handlers defined in the UserBalanceProjector class.
.Projects<UserBalanceView, Guid, UserBalanceProjector>();
});
});
🏗️ Architecture & Concurrency
In a distributed system, multiple events might try to update the same view at the exact same time. Tyto handles this robustly:
- Read: The Materializer loads the current View (e.g., Version 1).
- Project: It applies the logic from your
Projector. - Atomic Save: It attempts to save the new state (Version 2).
- Conflict Detection: If the underlying store detects that the version has changed (e.g., someone else saved Version 2 before we could), it throws a
ConcurrencyException. - Retry: Tyto automatically catches this exception, reloads the fresh data (Version 2), re-applies your projection logic, and attempts to save again.
This guarantees Strong Eventual Consistency. Updates are never lost, and the final state is always the result of applying events in order.
🧩 Advanced Usage
Manual Projector Registration
If you prefer explicit registration over reflection/auto-discovery, or if you have different classes handling different events for the same view:
// Register handlers explicitly
.Projects<UserBalanceView, Guid, UserRegistered, UserBalanceProjector>()
.Projects<UserBalanceView, Guid, MoneyDeposited, AnotherProjector>()
In-Memory Provider
For Unit Testing, use the In-Memory provider. It simulates serialization and concurrency conflicts to ensure your logic is production-ready.
.Store.UseInMemory()
Dependency Injection
Because Projectors are resolved from the DI container, you can use any registered service (Repositories, Anti-Corruption Layers, etc.) within your ProjectAsync methods.
public class OrderProjector(IExchangeRateService rateService) : IViewProjector<OrderView, OrderPlaced>
{
public async ValueTask ProjectAsync(OrderView view, OrderPlaced @event, CancellationToken ct)
{
var rate = await rateService.GetCurrentRateAsync(ct);
view.Total = @event.Amount * rate;
}
}
| 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
- Tyto.Abstractions (>= 0.0.1-alpha.47)
- Tyto.DependencyInjection (>= 0.0.1-alpha.47)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Tyto.Materializer:
| Package | Downloads |
|---|---|
|
Tyto.Materializer.EntityFrameworkCore
Package Description |
|
|
Tyto.Materializer.InMemory
Package Description |
|
|
Tyto.Materializer.Redis
Redis storage provider for Tyto.Materializer using Lua scripts and binary serialization. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.0.1-alpha.47 | 52 | 2/26/2026 |
| 0.0.1-alpha.46 | 53 | 2/22/2026 |
| 0.0.1-alpha.45 | 50 | 2/21/2026 |
| 0.0.1-alpha.44 | 53 | 2/21/2026 |
| 0.0.1-alpha.43 | 50 | 2/21/2026 |
| 0.0.1-alpha.42 | 52 | 2/20/2026 |
| 0.0.1-alpha.41 | 51 | 2/20/2026 |
| 0.0.1-alpha.40 | 49 | 2/20/2026 |
| 0.0.1-alpha.39 | 48 | 2/16/2026 |
| 0.0.1-alpha.38 | 50 | 2/15/2026 |
| 0.0.1-alpha.37 | 51 | 2/15/2026 |
| 0.0.1-alpha.36 | 49 | 2/15/2026 |
| 0.0.1-alpha.35 | 54 | 2/11/2026 |
| 0.0.1-alpha.34 | 53 | 2/11/2026 |
| 0.0.1-alpha.33 | 56 | 2/7/2026 |
| 0.0.1-alpha.32 | 60 | 1/26/2026 |
| 0.0.1-alpha.31 | 52 | 1/20/2026 |
| 0.0.1-alpha.30 | 51 | 1/17/2026 |
| 0.0.1-alpha.29 | 55 | 1/17/2026 |
| 0.0.1-alpha.28 | 60 | 1/14/2026 |