-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[release/8.0] Fix support of FromKeyedServicesAttribute in ActivatorUtilities.CreateFactory #92144
Conversation
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue DetailsBackport of #92082 to release/8.0 /cc @benjaminpetit Customer ImpactTestingRiskIMPORTANT: If this backport is for a servicing release, please verify that:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some perf impact due do the added reflection step to check attributes on constructor parameters. The result of ActivatorUtilities.CreateFactory is typically only called once per type and then cached by the application, so it should not have an impact too big.
I see @steveharter has reviewed this so I trust he's weighed in on the perf risk. I see our benchmarks also treat CreateFactory as something called once: /~https://github.com/dotnet/performance/blob/6cf8107895d5374c21983dd7ad09f711b389f247/src/benchmarks/micro/libraries/Microsoft.Extensions.DependencyInjection/ActivatorUtilitiesBenchmark.cs#L54-L57
Both the reflection and Linq.Expressions implementations of CreateFactory are already very heavy -> so I agree that this is a low risk.
Approved as this is a blocking issue in a new 8.0 feature. @artl93 please review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
M2 approved.
Backport of #92082 to release/8.0
Fixes #92076
/cc @benjaminpetit
Customer Impact
Without this fix, keyed DI does not work when using
ActivatorUtilities.CreateFactory
. This impact notably MVC and SignalR, and make it impossible to use keyed DI in controller and hub constructors.Testing
Test cases added in this PR, and also manually tested that the fix works in MVC.
Risk
Some perf impact due do the added reflection step to check attributes on constructor parameters. The result of
ActivatorUtilities.CreateFactory
is typically only called once per type and then cached by the application, so it should not have an impact too big.If the attribute doesn't exist, the existing logic should not have changed.