Repository navigation
Preserve native constructor rules through decoration (#111) - #118
Conversation
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
|
Implemented #111 in PR #118, awaiting review at Original implementation-type descriptors now use the existing native-compatible activator: ignore ActivatorUtilitiesConstructor attributes, accept native-valid parameter permutations/subsets, and reject unrelated parameter-type ambiguity before dependency activation. Keyed originals retain their actual service key; unkeyed originals receive no private decoration-slot key. Original factory delegates and instances, nonempty DependsOn maps, and newly added decorators keep their existing policies and ownership. As explicitly approved, plain BuildServiceProvider() remains supported. Built-in availability checks share the existing guarded descriptor fallback. Generic-constraint validation prefers Mammoth's snapshot and otherwise weakly caches an internal snapshot from the recognized native probe's copied descriptors. Public probes cannot detect invalid constraints on unselected candidates; resolving dependencies to test them would invoke factories too early. This reuses the existing private field lookup, adds no new private lookup, and preserves exact/AnyKey precedence and metadata isolation. The architecture document and source comments explain this version-sensitive fallback. Tests were added first: 144 failed, 135 controls passed per target before the fix, including a repeat with the corrected final validation control. All 279 new cases now pass, covering constructor selection, contextual keys, repeated layers, all lifetimes, type/factory/instance ownership, disposal, built-ins, generic constraints/overrides, metadata isolation, exceptions and retained decorator/map policies. Final local Release restore/build/full suite passed: 2,257 tests per target, 9,028 total, zero failed/skipped, on Windows net472 and net8.0/net9.0/net10.0. All four native hot-cache probes passed 100 interleaved enumerations after compilation. Only the two existing net472 support warnings for Telemetry.Abstractions and Diagnostics.Testing 10.0.0 remain; no compiler/analyzer warnings. CI run 37806283550 passed for the exact final head; downloaded logs confirm all test totals and cache probes. Pack and Publish were skipped. No applicable check was unavailable. The vNext changelog is updated. Stopping for your review and explicit instruction to continue. |
Adding a forwarding decorator currently changes the original type registration's constructor selection: it honors ActivatorUtilitiesConstructor attributes that native DI ignores, rejects valid parameter permutations, and accepts native-invalid ambiguity.
Use the existing native-compatible activator for original implementation-type descriptors. Pass the original requested key for keyed registrations and null for unkeyed registrations so private layer identities cannot become injected service keys. Existing factory delegates, nonempty DependsOn maps and newly added decorators retain their construction policies.
Closes #111.
Native-provider compatibility and metadata
The maintainer explicitly approved preserving plain BuildServiceProvider() support with the guarded fallback. The activator shares the existing keyed-built-in registration helper and obtains generic-constraint metadata from Mammoth's snapshot, or from the recognized native probe's copied descriptors. Native constructor selection checks open-generic constraints even for unselected candidates; public availability probes cannot do so without additional metadata. Resolving candidate dependencies to test them would activate factories before selection is complete.
This reuses the same private descriptor field lookup introduced for #108, adds no private member lookup, and caches the additional internal snapshot weakly per provider probe. Exact closed and AnyKey precedence, immutable built-provider metadata, zero activation during rejected selection and custom probe availability contracts are preserved. Private DI metadata remains a version-sensitive dependency; the recognized-native shape guard still fails clearly if unavailable. The existing architecture document, linked from source comments and README Architecture, now explains both uses.
Native rule reference: DI 10 constructor call-site creation.
Verification
Final commit:
e3feae6835e68c5a7edee4f0839eb9a1af805ad0.Includes vNext changelog and explanatory code/documentation comments. Work stops for review after exact-head CI verification.
Co-authored-by: Codex codex@openai.com