F# codegen: scoped-DI frame emit + 2.2.6 (#397)#398
Merged
Conversation
A generated method that resolves a scoped service via service location uses two
JasperFx.CodeGeneration.Services frames with no F# emit, so any handler injecting
a scoped dependency (EF Core DbContext, Marten IDocumentSession, …) threw on the
F# render.
- ScopedContainerCreation: `use serviceScope = ServiceProviderServiceExtensions
.CreateAsyncScope(serviceScopeFactory)` inside a task { } body (the CE's `use`
awaits DisposeAsync), or `use serviceScope = serviceScopeFactory.CreateScope()`
for a synchronous body; then postprocessors, then Next.
- GetServiceFromScopedContainerFrame: `let x = ServiceProviderServiceExtensions
.GetRequiredService<T>(scoped)` (or GetRequiredKeyedService). The optional C#
/* */ Header comment is not emitted on the F# path (invalid F# comment syntax).
- Fixture: GeneratedScopedConsumer resolves an AddScoped<T>(_ => …) lambda-factory
dependency (forcing service location) and awaits it; the compile gate proves the
scoped-DI F# compiles. Mirrors Bug_244's scoped-session scenario.
- Bump JasperFxVersion 2.2.5 -> 2.2.6.
Closes #397.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Closes #397. Ships as 2.2.6.
Problem
A generated method that resolves a scoped service via service location uses
ScopedContainerCreation+GetServiceFromScopedContainerFrame(JasperFx.CodeGeneration.Services), neither of which emitted F#. So any handler injecting a scoped dependency — EF CoreDbContext, MartenIDocumentSession, most real handlers — threwNotSupportedExceptionon the F# render.Fix
ScopedContainerCreation→use serviceScope = ServiceProviderServiceExtensions.CreateAsyncScope(serviceScopeFactory)inside atask { }body (the CE'suseawaitsDisposeAsyncon theAsyncServiceScope), oruse serviceScope = serviceScopeFactory.CreateScope()for a synchronous body; then postprocessors, thenNext. (F#usedisposes at end of scope, likeusing var.)GetServiceFromScopedContainerFrame→let x = ServiceProviderServiceExtensions.GetRequiredService<T>(scoped)/…GetRequiredKeyedService<T>(scoped, key). The optionalHeader(a C#-style/* */comment fragment) is not emitted on the F# path — those delimiters are invalid F#.Test
New
GeneratedScopedConsumerfixture resolves anAddScoped<IScopedThing>(_ => …)lambda-factory dependency (forcing service location) and awaits it twice, so the compile gate proves the scoped-DI F# compiles:Verification
CodegenTestsF# generation tests 30/30;CodegenTests.FSharpcompile gate green.Bumps
JasperFxVersion2.2.5 → 2.2.6 (RuntimeCompiler untouched).🤖 Generated with Claude Code