Fix #4787 — consume JasperFx 2.18.1 (DI-projection partial-class dispatch)#4794
Merged
Merged
Conversation
…atch) The 2.14.1 GetUninitializedObject fallback in EvolverCodeEmitter (#470) closed CS7036 for DI-only-ctor projections at compile time but left every injected field NULL at runtime — the file-scoped Evolver built its private shadow projection via RuntimeHelpers.GetUninitializedObject and dispatched every Apply/Create/ShouldDelete through it, so the DI-resolved projection that AddProjectionWithServices supplied was never used for event dispatch. Reporter's null-conditional masked the resulting NRE as silent zero events. JasperFx 2.18.1 (#481) fixes this in the source generator: when a projection has at least one instance-on-projection convention method AND no public parameterless ctor AND is partial, the generator now emits a [GeneratedCode]-attributed override (Evolve / EvolveAsync / DetermineActionAsync — picked by HasShouldDelete / HasAnyAsync exactly like the existing file-scoped Evolver) directly into the user's partial class. Body uses bare convention-method calls so dispatch binds to `this` — the DI-built instance with all injected fields populated. The [assembly: GeneratedEvolver(...)] attribute and the file sealed class Evolver are NOT emitted for this case — the runtime's isOverridden(...) precedence picks up the partial-class override before tryUseAssemblyRegisteredEvolver ever runs, so the shadow-instance code path (and the GetUninitializedObject line that introduced the regression in 2.14.1) goes away for DI projections entirely. Stateless / parameterless-ctor / aggregate-only / static-only projections keep the file-scoped Evolver verbatim — no perf or shape change for the cases that don't need DI. Marten side: - Bump JasperFx + JasperFx.Events + both source generators 2.18.0 → 2.18.1. - Promote Bug_4787_di_projection_with_instance_apply (originally on the repro branch repro/4787-di-projection-ctor-skipped) into the regression suite. 9 cases — Apply/Create/ShouldDelete × Singleton/Scoped/Transient — ALL FAILED with NRE through the shadow instance on 2.18.0, ALL PASS on 2.18.1. The ContainerScopedProjectionTests project is the right home (it's the only suite that exercises AddProjectionWithServices end-to-end). Closes #4787 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Jun 30, 2026
Merged
This was referenced Jul 9, 2026
This was referenced Jul 20, 2026
This was referenced Jul 21, 2026
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.
Consumes the JasperFx 2.18.1 source-generator fix from jasperfx#481 that lands the partial-class override emission path for DI-only-ctor projections.
What this closes
A
partial SingleStreamProjection<T, TId>registered viaAddProjectionWithServiceswith constructor-injected dependencies and conventional instance methods (Create/Apply/ShouldDelete) had its injected fields silently NULL inside every convention method on Marten 9.11+ / JasperFx.Events 2.14.x+. The reporter's_sender?.SendAsync(...)null-conditional masked the resulting NRE as silent zero events.How JasperFx 2.18.1 fixes it
The 2.14.1 fallback in
EvolverCodeEmitterclosed CS7036 for DI-only-ctor projections at compile time but left every injected field NULL at runtime — the file-scoped Evolver built its private shadow projection viaRuntimeHelpers.GetUninitializedObjectand dispatched everyApply/Create/ShouldDeletethrough it, so the DI-resolved projection thatAddProjectionWithServicessupplied was never used for event dispatch.2.18.1 emits a
[GeneratedCode]-attributed override (Evolve/EvolveAsync/DetermineActionAsync— picked byHasShouldDelete/HasAnyAsyncexactly like the existing file-scoped Evolver) directly into the user's partial class. Body uses bare convention-method calls so dispatch binds tothis— the DI-built instance with all injected fields populated. The[assembly: GeneratedEvolver(...)]attribute and thefile sealed classEvolver are NOT emitted for this case — the runtime'sisOverridden(...)precedence picks up the partial-class override beforetryUseAssemblyRegisteredEvolverever runs.Stateless / parameterless-ctor / aggregate-only / static-only projections keep the file-scoped Evolver verbatim — no perf or shape change for cases that don't need DI.
Changes
Directory.Packages.props: JasperFx + JasperFx.Events + both source generators 2.18.0 → 2.18.1.src/ContainerScopedProjectionTests/Bug_4787_di_projection_with_instance_apply.cs: regression suite — 9 cases covering{Apply, Create, ShouldDelete}×{Singleton, Scoped, Transient}. All 9 failed on 2.18.0 with NRE through the shadow instance. All 9 pass on 2.18.1. Originally on the repro branchrepro/4787-di-projection-ctor-skipped— now promoted to the regression suite in the project that exercisesAddProjectionWithServicesend-to-end.Test plan
Closes #4787
🤖 Generated with Claude Code