Fix IResolver/IContainer injected into singletons capturing scoped container instead of root#700
Draft
Copilot wants to merge 3 commits into
Draft
Fix IResolver/IContainer injected into singletons capturing scoped container instead of root#700Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
Agent-Logs-Url: https://github.com/dadhi/DryIoc/sessions/63e358b0-95a3-4f97-9b84-f310ea81041d Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
…ntainer instead of root Agent-Logs-Url: https://github.com/dadhi/DryIoc/sessions/63e358b0-95a3-4f97-9b84-f310ea81041d Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix singleton service resolved by scoped container
Fix IResolver/IContainer injected into singletons capturing scoped container instead of root
Apr 10, 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.
When a singleton is first resolved through a scoped container with
WithoutThrowIfDependencyHasShorterReuseLifespan(), any directly injectedIResolver/IResolverContext/IContainerdependency captures the scoped container instead of root — causing failures after scope disposal.Root cause
ResolverContext.GetRootOrSelfExpr()gates the use ofRootOrSelfExpronThrowIfDependencyHasShorterReuseLifespan(introduced for #378). When that rule is disabled, it falls back toResolverContextParamExpr— the current scope's resolver — even for container interfaces directly injected into singletons.Changes
ResolverContext.GetRootOrSelfExprForContainerInterface()— new internal method identical toGetRootOrSelfExpr()but without theThrowIfDependencyHasShorterReuseLifespanguard. Singletons must always receive the root container for direct interface injection regardless of captive-dependency rules.AddContainerInterfaces()— switched all five container interface wrappers (IResolver,IResolverContext,IContainer,IRegistrator,IServiceProvider) to use the new method.The
ThrowIfDependencyHasShorterReuseLifespancondition is preserved in the originalGetRootOrSelfExpr()used byCreateResolutionExpression, soLazy<ScopedService>inside a singleton still correctly resolves through the scope resolver (#378 behavior unaffected).Tests added
GHIssue686_Singleton_service_resolved_by_scoped_container_not_root_containercovering:IResolverin singleton resolved first via scope withWithoutThrowIfDependencyHasShorterReuseLifespanIContainervariantLazy<ScopedService>in singleton still works (regression for Inconsistent resolution failure #378)