Skip to content

Fix wrong decorator parameter when resolving with custom args - #702

Draft
dadhi with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-decorator-parameter-issue
Draft

Fix wrong decorator parameter when resolving with custom args#702
dadhi with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-decorator-parameter-issue

Conversation

Copilot AI commented Apr 10, 2026

Copy link
Copy Markdown

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, TryGetExpressionFromInputArgs uses IsAssignableFrom matching. For a decorator like DecoratorA(object t) applied to object, resolving with args: new object[] { DateTime.Now } would match DateTimeobject t (since object.IsAssignableFrom(DateTime)), bypassing the decorated service resolution entirely.

Fix

  • src/DryIoc/Container.cs: Skip input arg matching for a decorator parameter when paramType.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 disabled Assert.IsInstanceOf<B>(res) assertion in Original_case and added it to Run().

container.Register<object, B>(serviceKey: "xyz");
container.Register<object>(made: Made.Of(_ => decorateMethod), setup: Setup.DecoratorOf<A>());

// Previously: `t` received `now` (DateTime) instead of the decorated B instance
var res = container.Resolve<object>("xyz", args: new object[] { DateTime.Now });
Assert.IsInstanceOf<B>(res); // now passes

Copilot AI linked an issue Apr 10, 2026 that may be closed by this pull request
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
Copilot AI requested a review from dadhi April 10, 2026 06:39
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.

Wrong decorator parameter with custom args

2 participants