Skip to content

Honor [FromKeyedServices] on handler constructor params (closes #3081) - #3086

Merged
jeremydmiller merged 1 commit into
mainfrom
feat-3081-keyed-ctor-injection
Jun 12, 2026
Merged

jeremydmiller merged 1 commit into
mainfrom
feat-3081-keyed-ctor-injection

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Follow-up to JasperFx/jasperfx#445, which fixed the root cause of #3081. This bumps Wolverine to the published fix and adds an end-to-end regression test.

Background

#3081: a handler with [FromKeyedServices("…")] on its constructor parameters generated code that ignored the key — each keyed parameter was resolved by type only and fell through to the default (last) registration. With two keyed params of the same service type, both bound to the same instance (the reporter's new TestRepo2() for both).

Root cause was in JasperFx's ConstructorFrame.FindVariables, which resolved constructor parameters via the type-only FindVariable(Type) overload instead of the attribute-aware FindVariable(ParameterInfo) overload that MethodCall already used. That asymmetry is exactly why keyed services on a Handle(...) method parameter already worked but the same attribute on the handler constructor did not. Fixed in JasperFx 2.9.10.

Lamar's keyed resolution was already correct (verified directly in the Lamar repo — both at runtime and in its own generated build plan); the bug was container-agnostic, in the shared codegen layer.

Changes

  • JasperFx 2.8.2 → 2.9.10 (JasperFx, JasperFx.Events, JasperFx.Events.SourceGenerator, JasperFx.SourceGenerator; JasperFx.RuntimeCompiler stays on its 5.x line).
  • keyed_services_on_handler_constructor — a handler whose constructor takes two [FromKeyedServices] params of the same service type ("Test" → FirstRepo, "Test2" → SecondRepo); asserts each resolves to its own registration. Companion to the existing using_with_keyed_services (method-parameter case).
  • MessagePack 3.1.3 → 3.1.7 — clears the freshly-published NU1903 advisory that otherwise fails the build under TreatWarningsAsErrors (affects main too; bundled here to keep this PR's CI green).

Verification

  • New test passes; existing using_with_keyed_services (4) still pass; 267 CoreTests green.
  • wolverine.slnx -c Release builds clean — 0 warnings, 0 errors.

Note on Lamar

I did not add a Lamar-specific variant: Wolverine's test suite has no Lamar dependency, the bug reproduces identically on the default container (same ConstructorFrame codegen path), and Lamar's keyed correctness is covered in the Lamar repo. Happy to wire up a Lamar test if preferred.

🤖 Generated with Claude Code

…loses #3081)

JasperFx 2.9.10 fixes ConstructorFrame to resolve constructor parameters via the
attribute-aware FindVariable(ParameterInfo) overload, so [FromKeyedServices] on a
handler's constructor is honored (JasperFx/jasperfx#445). Before, keyed
constructor parameters were resolved by type only and fell through to the default
(last) registration — two keyed params of the same service type both bound to the
same instance.

- Bump JasperFx, JasperFx.Events, JasperFx.Events.SourceGenerator and
  JasperFx.SourceGenerator 2.8.2 -> 2.9.10 (RuntimeCompiler stays on its 5.x line).
- Add keyed_services_on_handler_constructor: a handler whose constructor takes two
  [FromKeyedServices] params of the same service type, asserting each resolves to
  its own registration. Companion to using_with_keyed_services, which covers keyed
  services on Handle METHOD parameters (that path already worked).
- Bump MessagePack 3.1.3 -> 3.1.7 to clear the NU1903 advisory that otherwise fails
  the build under TreatWarningsAsErrors.

Closes #3081

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jeremydmiller
jeremydmiller merged commit bafe1cf into main Jun 12, 2026
23 checks passed
jeremydmiller added a commit that referenced this pull request Jun 12, 2026
Follow-up to #3086. The #3081 fix (JasperFx 2.9.10) lives in the shared codegen
layer, so it applies to any container — but the issue was reported on Lamar, so
add an explicit Lamar variant of the keyed-constructor-injection test.

- Add Lamar.Microsoft.DependencyInjection to CoreTests (its transitive JasperFx
  unifies up to Wolverine's 2.9.10 — no version conflict).
- keyed_services_on_handler_constructor now runs the same scenario against both
  the default container and Host.CreateDefaultBuilder().UseLamar(), sharing one
  helper, asserting each [FromKeyedServices] constructor parameter resolves to its
  own registration.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 15, 2026
This was referenced Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant