Skip to content

Preserve native constructor rules through decoration (#111) - #118

Merged
AGiorgetti merged 3 commits into
developfrom
codex/fix-111-native-decorator-activation
Oct 9, 2026
Merged

AGiorgetti merged 3 commits into
developfrom
codex/fix-111-native-decorator-activation

Conversation

@AGiorgetti

@AGiorgetti AGiorgetti commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Tests were added and committed first. Pre-fix results: 144 failed and 135 passed per target on net472, net8.0, net9.0 and net10.0. The corrected final native validation control was rechecked against pre-fix source with the same results.
  • 279 new cases per target cover preferred/multiple/unavailable attributes, permutations/subsets/repeated parameters, optional defaults, rejected dependencies, shorter and equal-length ambiguity, contextual/exact/AnyKey keys, repeated layers, all lifetimes, type/factory/instance ownership, keyed built-ins, generic constraints and exact/wildcard overrides, metadata isolation, exception types and existing decorator/map policies.
  • Release restore and solution build passed, including netstandard2.0.
  • Full suite passed 2,257 tests per target, 9,028 total, zero failed/skipped.
  • Native cache probes passed on all four targets: 100 interleaved enumerations after observed native accessor compilation.
  • Windows net472 executed on .NET Framework 4.8.9345.0; other local runtimes: .NET 8.0.31, 9.0.20, 10.0.12.
  • Whitespace check passed. Only the existing net472 support warnings from Microsoft.Extensions.Telemetry.Abstractions 10.0.0 and Microsoft.Extensions.Diagnostics.Testing 10.0.0 remain; no compiler/analyzer warnings.
  • CI run 37806283550 passed for this exact head. Downloaded logs confirm 2,257 passing tests on all four targets and all four native cache probes. Pack and Publish were skipped. No applicable check was unavailable.

Includes vNext changelog and explanatory code/documentation comments. Work stops for review after exact-head CI verification.

Co-authored-by: Codex codex@openai.com

AGiorgetti and others added 3 commits October 8, 2026 17:51
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>

Copy link
Copy Markdown
Contributor Author

Implemented #111 in PR #118, awaiting review at e3feae6835e68c5a7edee4f0839eb9a1af805ad0.

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.

@AGiorgetti
AGiorgetti marked this pull request as ready for review October 9, 2026 08:09
@AGiorgetti
AGiorgetti merged commit d60064f into develop Oct 9, 2026
2 checks passed
@AGiorgetti
AGiorgetti deleted the codex/fix-111-native-decorator-activation branch October 9, 2026 08:12
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.

Decoration changes native type-registration constructor preference and ambiguity rules

1 participant