Draft
Fix wrong decorator parameter when resolving with custom args#702
Conversation
…ameter Agent-Logs-Url: https://github.com/dadhi/DryIoc/sessions/61078f49-05b0-453e-8f6f-d70776a35dd7 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dadhi/DryIoc/sessions/61078f49-05b0-453e-8f6f-d70776a35dd7 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix wrong decorator parameter with custom args
Fix wrong decorator parameter when resolving with custom args
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 resolving a service with custom
args, a decorator's "decorated service" parameter incorrectly received an input arg (matched by type compatibility) instead of the actual decorated service instance.Root Cause
In
ReflectionFactory.CreateExpressionOrDefault,TryGetExpressionFromInputArgsusesIsAssignableFrommatching. For a decorator likeDecoratorA(object t)applied toobject, resolving withargs: new object[] { DateTime.Now }would matchDateTime→object t(sinceobject.IsAssignableFrom(DateTime)), bypassing the decorated service resolution entirely.Fix
src/DryIoc/Container.cs: Skip input arg matching for a decorator parameter whenparamType.IsAssignableFrom(request.ServiceType)— i.e., when the parameter type can hold the decorated service. Such parameters are resolved normally through the container (inheriting the service key), while other decorator parameters with distinct types still receive input args.test/.../GHIssue672_Wrong_decorator_parameter_with_custom_args.cs: Enabled the previously disabledAssert.IsInstanceOf<B>(res)assertion inOriginal_caseand added it toRun().