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

[release/8.0] Fix support of FromKeyedServicesAttribute in ActivatorUtilities.CreateFactory #92144

Merged
merged 2 commits into from
Sep 16, 2023

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Sep 15, 2023

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.

@ghost
Copy link

ghost commented Sep 15, 2023

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

Issue Details

Backport of #92082 to release/8.0

/cc @benjaminpetit

Customer Impact

Testing

Risk

IMPORTANT: If this backport is for a servicing release, please verify that:

  • The PR target branch is release/X.0-staging, not release/X.0.

  • If the change touches code that ships in a NuGet package, you have added the necessary package authoring and gotten it explicitly reviewed.

Author: github-actions[bot]
Assignees: -
Labels:

area-Extensions-DependencyInjection

Milestone: -

@steveharter steveharter added this to the 8.0.0 milestone Sep 15, 2023
@ericstj ericstj added the Servicing-consider Issue for next servicing release review label Sep 16, 2023
Copy link
Member

@ericstj ericstj left a 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.

Copy link
Contributor

@artl93 artl93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M2 approved.

@artl93 artl93 added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 16, 2023
@ericstj ericstj merged commit c7252a3 into release/8.0 Sep 16, 2023
107 of 112 checks passed
@jkotas jkotas deleted the backport/pr-92082-to-release/8.0 branch September 16, 2023 13:18
@radical radical mentioned this pull request Sep 26, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants