Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Playground for flavors of declarative projections in C# ... seeking the DSL so to speak
// TState is an individual, immutable state entry in the projection state
// Flavor 1:
Projection<TState>.
When<TEvent>.ThenAdd<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TEvent, TState> handler).
When<TEvent>.ThenUpdate<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TState, TEvent, TState> handler).
When<TEvent>.ThenAddOrUpdate<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TEvent, TState> addHandler, Func<TState, TEvent, TState> updateHandler)
When<TEvent>.ThenRemove<TKey, TEvent>(Func<TEvent, TKey> selector)
// TState is an individual, immutable state entry in the projection state
// Flavor 2: Add & Update melted into Set leaving the host to deal with Add or Update semantics
Projection<TState>.
When<TEvent>.ThenSet<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TState, TEvent, TState> handler).
When<TEvent>.ThenRemove<TKey, TEvent>(Func<TEvent, TKey> selector)
// TState is the entire projection state
// Flavor 3: Immutable state. Courtesy of @gregyoung
Projection<TState>.
When<TEvent>(Func<TState, TEvent, TState> handler)
// TState is the entire projection state
// Flavor 4: Mutable state. Courtesy of @peterhagues
Projection<TState>.
When<TEvent>(Action<TState, TEvent> handler)
// Look ma, no state. Courtesy of @gregyoung
// Flavor 5:
Projection.
When<TEvent>(Action<TEvent> handler)
// Projac style.
// Flavor 6:
Projection.
When<TEvent>(Func<TEvent, IEnumerable<TSqlNonQueryStatement>> handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.