Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chaining identical decorators causes incorrect diagnostic error #925

Closed
dotnetjunkie opened this issue Sep 13, 2021 · 3 comments
Closed
Labels
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

The details for this bug can be found here: https://stackoverflow.com/questions/69155688/simpleinjector-how-to-reuse-a-decorator-class-more-than-once-in-objects-decora

container.Register<ITarget, Target>(Lifestyle.Scoped);
container.RegisterDecorator(typeof(ITarget), typeof(InstrumentationTargetDecorator), Lifestyle.Scoped);
container.RegisterDecorator(typeof(ITarget), typeof(ResilienceTargetDecorator), Lifestyle.Scoped);
container.RegisterDecorator(typeof(ITarget), typeof(InstrumentationTargetDecorator), Lifestyle.Scoped);

Error:

-[Ambiguous Lifestyles] The registration for ITarget (Async Scoped) maps to the same implementation (InstrumentationTargetDecorator) as the registration for ITarget (Scoped) does, but the registration maps to a different lifestyle. This will cause each registration to resolve to a different instance.

@dotnetjunkie
Copy link
Collaborator Author

Branch bug-925 created.

@dotnetjunkie
Copy link
Collaborator Author

Workaround:

// Make a derivative of the duplicate decorator and register this
class Derivative: InstrumentationTargetDecorator { ...}

container.Register<ITarget, Target>(Lifestyle.Scoped);
container.RegisterDecorator(typeof(ITarget), typeof(InstrumentationTargetDecorator), Lifestyle.Scoped);
container.RegisterDecorator(typeof(ITarget), typeof(ResilienceTargetDecorator), Lifestyle.Scoped);
container.RegisterDecorator(typeof(ITarget), typeof(Derivative), Lifestyle.Scoped);

dotnetjunkie added a commit that referenced this issue Oct 30, 2021
@dotnetjunkie dotnetjunkie added this to the Simple Injector v5.3.3 milestone Jan 29, 2022
@dotnetjunkie
Copy link
Collaborator Author

A fix for this issue has been implemented in v5.3.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant