Create AnyKey adapter registrations per registry (#1497) - #1498
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1498 +/- ##
===========================================
- Coverage 78.26% 78.23% -0.03%
===========================================
Files 218 217 -1
Lines 5948 5928 -20
Branches 1274 1269 -5
===========================================
- Hits 4655 4638 -17
Misses 753 753
+ Partials 540 537 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The adapter cache handed one registration to every registry that asked for it, so the scope that got there first built its pipeline and disposed it - leaving other scopes unable to add middleware (#1497), resolving through a disposed activator, or adapting another scope's registration.
Microsoft.SourceLink.GitHub 8.0.0 brings Microsoft.Build.Tasks.Git 8.0.0, which the advisory has no patched 8.x release for, so NuGet audit fails the Release build. VerifyAotWarnings ignored the fixture's exit code, which turned that restore failure into a claim that an AOT annotation had been lost - it now reports the build failure instead.
tillig
force-pushed
the
feature/issue-1497
branch
from
September 15, 2026 17:00
a37200f to
53020b9
Compare
This was referenced Sep 18, 2026
This was referenced Sep 25, 2026
This was referenced Sep 25, 2026
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.
Fixes #1497
Proposed Changes
AnyKeyRegistrationSourceno longer caches the adapter registrations it creates. The cache added in Performance improvements #1478 is keyed only by the requestedKeyedService, but the source instance is shared with every child scope registry, so one adapter instance got handed to several registries. A registry owns the registrations added to it - it builds their pipelines and disposes them - and an adapter has to target the any-key registration visible in the registry that asked for it. Sharing one broke all three:Autofac.Extensions.DependencyInjectionadds middleware fromRegistered, which throwsInvalidOperationExceptionon a registration whose pipeline another registry already built. This is the reported symptom.ObjectDisposedException. No MEDI involved.ReflectionCacheKeyedServiceDictionary, which existed only to hold that cache.KeyedAnyKeyChildScopeBenchmarkto cover the affected path.Regression Tests
Four tests in
AnyKeyRegistrationSourceTests: one per symptom above, plus the invariant that two registries never hold the same adapter instance. All four fail against 9.3.2.Performance
dotnet run -c Release --project bench/Autofac.Benchmarks -- --baseline-version 9.3.2 --filter *KeyedAnyKeyChildScope*, net10.0:ResolveDirectKeyFromNewChildScope(control, no any-key)ResolveAnyKeyFromExistingChildScopeResolveAnyKeyFromNewChildScopeOnly the path that now builds an adapter per registry moves: roughly 850 ns and 2.8 KB per new scope registry, against the direct-keyed control in the same run. It has no baseline number because every released version with any-key support throws
ObjectDisposedExceptionthere.KeyedAnyKeySimpleBenchmarkand the root container resolves are unchanged.Unblocking CI
Two commits: the fix above, plus one for CI, which was already failing on
develop.Microsoft.SourceLink.GitHub8.0.0 → 10.0.401. It carriesMicrosoft.Build.Tasks.Git8.0.0, which CVE-2026-62900 covers with no patched 8.x release, so NuGet audit fails the Release build. Every other repo in the org is already on 10.0.3xx/4xx.VerifyAotWarningsignored the fixture build's exit code, so that restore failure surfaced as "an annotation may have been lost in core Autofac" instead of the actual error. It now checks the exit code first.Sibling repos pinning 10.0.300 or 10.0.301 are in the same advisory range and will hit this too.