Commit 7b27543
committed
Switch LamarServiceDescriptor to factory-shape base ctor
The (Type, Type, ServiceLifetime) base ctor on LamarServiceDescriptor made
the descriptor look like a normal concrete-type registration to external
consumers. Wolverine HTTP code-gen reads that as "I can inline-construct
this" and walks the impl's ctor chain — which fails as
'NotSupportedException: Cannot build service type ... in any way' whenever
a ctor parameter is registered only via Lamar's convention scan (scan-only
deps don't surface to the IServiceCollection snapshot Wolverine reads).
Per Wolverine's docs, an "opaque lambda factory" descriptor with a
Scoped or Transient lifetime makes Wolverine fall back to service location
at runtime — exactly the path we want, since service location goes through
Lamar's IServiceProvider, which can resolve scan-only deps.
Changing the base ctor to (Type, Func, ServiceLifetime) flips the
descriptor's external shape to that opaque-factory form, eliminating the
inline-construction code-gen path entirely. Lamar's own self-discovery is
unaffected — Instance.For checks for the LamarServiceDescriptor subclass
first and returns the typed Instance property, bypassing the
ImplementationFactory branch.
The factory delegate itself throws if invoked: Wolverine service-locates
without calling it, and Lamar's resolution path uses the subclass's Instance
property, so the only way to reach the delegate is via a non-Lamar
IServiceProvider — which is misuse this descriptor isn't designed for.
Verified end-to-end against a Wolverine HTTP endpoint that constructor-
captures IAsyncDocumentSession through a chain of services including
scan-only deps: three concurrent POST requests now succeed with HTTP 200
and distinct session + factory identity hashes (was: same hash and a
Raven 'Concurrent usage of async tasks' exception under the legacy
Lamar bridge, then 'Cannot build service type' under the intermediate
concrete-type-base-ctor fix).
All 714 tests in Lamar.Testing pass on net8.0, net9.0, net10.0.
All 23 tests in Lamar.AspNetCoreTests pass on all three TFMs.1 parent 1d64e61 commit 7b27543
1 file changed
Lines changed: 24 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
29 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
34 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
35 | 51 | | |
0 commit comments