Hapnd.Projections.Contracts
0.2.0
dotnet add package Hapnd.Projections.Contracts --version 0.2.0
NuGet\Install-Package Hapnd.Projections.Contracts -Version 0.2.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="Hapnd.Projections.Contracts" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hapnd.Projections.Contracts" Version="0.2.0" />
<PackageReference Include="Hapnd.Projections.Contracts" />
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 Hapnd.Projections.Contracts --version 0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Hapnd.Projections.Contracts, 0.2.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 Hapnd.Projections.Contracts@0.2.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=Hapnd.Projections.Contracts&version=0.2.0
#tool nuget:?package=Hapnd.Projections.Contracts&version=0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Hapnd Projections Contracts
Contracts for building projections and reducers for Hapnd - the event sourcing platform built for engineers.
Installation
dotnet add package Hapnd.Projections.Contracts
Usage
Implement IReducer<TState> to define how events transform into aggregate state:
using Hapnd.Projections.Contracts;
public record OrderState
{
public decimal Total { get; init; }
public List<string> Items { get; init; } = [];
public int ItemCount { get; init; }
}
public class OrderReducer : IReducer<OrderState>
{
public OrderState Apply(OrderState? state, Event @event)
{
state ??= new OrderState();
return @event.Type switch
{
"ItemAdded" => ApplyItemAdded(state, @event.GetData<ItemAddedData>()),
"ItemRemoved" => ApplyItemRemoved(state, @event.GetData<ItemRemovedData>()),
_ => state
};
}
object? IProjection.Apply(object? state, Event @event)
=> Apply((OrderState?)state, @event);
private static OrderState ApplyItemAdded(OrderState state, ItemAddedData data)
{
return state with
{
Total = state.Total + data.Price,
Items = state.Items.Append(data.Item).ToList(),
ItemCount = state.ItemCount + 1
};
}
private static OrderState ApplyItemRemoved(OrderState state, ItemRemovedData data)
{
return state with
{
Total = state.Total - data.Price,
Items = state.Items.Where(i => i != data.Item).ToList(),
ItemCount = Math.Max(0, state.ItemCount - 1)
};
}
}
public record ItemAddedData(string Item, decimal Price);
public record ItemRemovedData(string Item, decimal Price);
Strongly-Typed Event Data
Use Event.GetData<T>() to deserialize event data with full type safety:
var data = @event.GetData<ItemAddedData>();
Console.WriteLine($"Added {data.Item} for {data.Price:C}");
Packaging Your Projection
- Create a class library project referencing this package
- Implement your projection/reducer
- Build and zip the output
- Upload to Hapnd via
POST /projections/uploadorPOST /reducers/upload
Requirements
- .NET 10.0 or later
License
Apache 2.0
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- No dependencies.
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.2.0 | 110 | 4/24/2026 |