F# codegen: Marten event-sourced aggregate slice — runnable sample + compile-gate (GH-2969)#2985
Merged
Merged
Conversation
Third store-specific slice of the F# code-generation audit (the heaviest frame set): a runnable F# Wolverine + Marten event-sourcing app and a compile-gate proving its [<AggregateHandler>] chain emits valid F#. Marten aggregate frame F# emit (all Wolverine.Marten/Codegen, no JasperFx release): - LoadAggregateFrame -> `let! stream = session.Events.FetchForWriting<Agg>(id, ct)` (covers natural-key, exclusive, and versioned overloads; AlwaysEnforceConsistency <- true). - TagAggregateOtelFrame -> guarded `Activity.Current.SetTag(...) |> ignore` (no `?.` in F#). - MissingAggregateCheckFrame -> `if isNull stream.Aggregate then raise(UnknownAggregateException(typeof<Agg>, id))`. RegisterEvents (AppendOne) + SaveChanges are MethodCall/already-F# frames. Runnable sample (src/Samples/WolverineMartenAggregateFSharpSample): - F# Counter aggregate + CounterStarted/Incremented events + an [<AggregateHandler>] IncrementHandler. Seeds a stream, then increments it (load via FetchForWriting, append the returned event). Postgres-backed, dynamic codegen (Wolverine.RuntimeCompilation + UseRuntimeCompilation, GH-2876). Verified end-to-end: "Incremented the Counter through the F# Wolverine + Marten aggregate handler." - KEY F# constraint: Marten's convention Create/Apply aggregation is dispatched by the C#-only JasperFx.Events source generator, which does not run for F#. CounterProjection therefore overrides Evolve directly (an explicit per-event fold) — the supported escape hatch for F# self-aggregating types. Compile-gate (src/Testing/Wolverine.MartenAggregate.FSharp{Tests,Fixture}): - Renders the sample's real IncrementCounter chain to F# via the no-host HandlerGraph/AssembleTypes/GenerateFSharpCode path and dotnet-builds the fixture. The gate driver does not register the projection (codegen only emits FetchForWriting<Counter>). Wire-up: sample + gate added to wolverine_fsharp.slnx; fsharp.yml runs the aggregate gate as its own sequential step. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8 tasks
This was referenced Jun 1, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the F# code-generation audit (#2969), following the EF Core (#2983) and Marten document (#2984) slices. This is the third store-specific slice: Marten event sourcing — the heaviest frame set — with its own runnable F# sample + compile-gate.
Marten aggregate frame F# emit
All in
Wolverine.Marten/Codegen— no JasperFx release needed (all Wolverine-side):LoadAggregateFrame→let! stream = session.Events.FetchForWriting<Agg>(id, ct)(covers the natural-key, exclusive-writing, and versioned overloads;stream.AlwaysEnforceConsistency <- true).TagAggregateOtelFrame→ guardedActivity.Current.SetTag(...) |> ignore(no?.in F#).MissingAggregateCheckFrame→if isNull stream.Aggregate then raise(UnknownAggregateException(typeof<Agg>, id)).RegisterEvents(AppendOne) andSaveChangesAsyncareMethodCall/already-F# frames.Generated F# (from the gate):
Runnable sample —
src/Samples/WolverineMartenAggregateFSharpSampleF#
Counteraggregate +CounterStarted/Incrementedevents + an[<AggregateHandler>]IncrementHandler. Seeds a stream, then increments it (load viaFetchForWriting, append the returned event). Postgres-backed; dynamic codegen (Wolverine.RuntimeCompilation+opts.UseRuntimeCompilation(), #2876). Verified end-to-end: printsIncremented the Counter through the F# Wolverine + Marten aggregate handler.A key F# + Marten event-sourcing constraint
Marten's convention-based aggregation (
Create/Applymethods) is dispatched by the C#-onlyJasperFx.Eventssource generator, which does not run for F# assemblies. SoCounterProjectionoverridesEvolvedirectly (an explicit per-event fold) — the supported escape hatch for F# self-aggregating types. Documented in the sample README.Compile-gate —
src/Testing/Wolverine.MartenAggregate.FSharp{Tests,Fixture}Renders the sample's real
IncrementCounterchain to F# via the no-hostHandlerGraph→AssembleTypes→GenerateFSharpCodepath, thendotnet builds the fixture. The gate driver does not register the projection (codegen only emits theFetchForWriting<Counter>call). Mirrors the prior gates.Wire-up
wolverine_fsharp.slnx.fsharp.ymlruns the aggregate gate as its own sequential step.Verification
dotnet build wolverine.slnx -c Releaseclean (per CLAUDE.md the slim build isn't sufficient).Next up (separate work): an F# sample exercising FluentValidation middleware + CosmosDb persistence.
🤖 Generated with Claude Code