[release/7.0] Infer parameter source from ElementType for IEnumerable #45256
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.
Backport of #45173 to release/7.0
/cc @brunolins16
Infer parameter source from ElementType for IEnumerable
This PR addresses a bug shipped in .NET 7 where a parameter (
IEnumerable<>
) is incorrectly detected asFromService
.Fixes #45162
Customer Impact
In .NET 7 was introduced, in
API Controllers
andSignalR
, the feature to infer the source (FromServices
) for parameter types registered in the DI, however, the mechanism always detectsIEnumerable<>
as a type registered, since the CallSiteFactory is not explicit registering them and could they be created when requested, changing (unexpected) the behavior from .NET 6.This PR fixes both (
API Controllers
andSignalR
) to when aIEnumerable<>
parameter type is detected uses the Type Argument instead to check if it is registered in the DI, reverting to the .NET 6 behavior and keep the feature working.Regression?
The usage of
IEnumerable<>
parameters was working on .NET 6 and the regression introduced in .NET 7.Risk
This change is very limited to how the inference works and not changing the parameter binding itself.
Verification
Packaging changes reviewed?