fix: ServiceInterceptor AllowMultiple not respected due to .Distinct()#345
Closed
liuhaoyang wants to merge 57 commits into
Closed
fix: ServiceInterceptor AllowMultiple not respected due to .Distinct()#345liuhaoyang wants to merge 57 commits into
liuhaoyang wants to merge 57 commits into
Conversation
Remove .Distinct() from InterceptorCollector.Collect() because HandleMultiple() already correctly handles deduplication: - Interceptors with AllowMultiple=true are kept as-is (no dedup) - Interceptors with AllowMultiple=false are deduplicated by type The .Distinct() call was incorrectly deduplicating ServiceInterceptorAttribute instances that wrap the same inner interceptor type, because ServiceInterceptorAttribute.Equals() compares by _interceptorType. This caused ServiceInterceptor to effectively ignore AllowMultiple=true. Fixes #325
Member
Author
|
关闭此 PR,因为它错误地包含了 PR #334 的变更(分支基于错误的 base 创建)。已重新创建干净的 PR。 |
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.
Problem
ServiceInterceptorAttributedeclaresAllowMultiple = true, but multipleServiceInterceptorAttributeinstances wrapping the same inner interceptor type were being incorrectly deduplicated.Root Cause
In
InterceptorCollector.Collect(), the pipeline ends with:HandleMultiple()correctly keepsAllowMultipleinterceptors and deduplicates non-AllowMultipleones by type..Distinct()usesEquals()for deduplication.ServiceInterceptorAttribute.Equals()compares by_interceptorType, so two instances wrapping the same type are treated as equal.ServiceInterceptorAttribute.AllowMultiple = truewas effectively ignored.Fix
Removed
.Distinct()sinceHandleMultiple()already provides the correct deduplication semantics:AllowMultiple = true→ all instances keptAllowMultiple = false→ deduplicated by typeChanges
src/AspectCore.Core/DynamicProxy/InterceptorCollector.cs.Distinct()from theCollectpipelinetests/AspectCore.Tests/Integrate/ServiceInterceptorTests.cs[ServiceInterceptor]to execute (2 instead of 1); added test for single-attribute caseTest Results
Fixes #325