Skip to content

Conversation

@benjaminpetit
Copy link
Member

@benjaminpetit benjaminpetit commented Sep 14, 2023

Fixes #92076

Right now ActivatorUtilities.CreateFactory doesn't check if the constructor parameters have a FromKeyedServicesAttribute to get them from the keyed services container.

It will make ActivatorUtilities.CreateFactory slower since it involves more reflection, but CreateFactory should be called only once per type, and the factory created can be cached and called multiple times by the application, so it should not impact performance too much.

ASP.NET Core MVC and SignalR need this feature for 8.0.

@ghost
Copy link

ghost commented Sep 14, 2023

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

Issue Details

Fix for #92076

Right now ActivatorUtilities.CreateFactory doesn't check if the constructor parameters have a FromKeyedServicesAttribute to get them from the keyed services container.

It will make ActivatorUtilities.CreateFactory slower since it involves more reflection, but CreateFactory should be called only once per type, and the factory created can be cached and called multiple times by the application, so it should not impact performance too much.

ASP.NET Core MVC and SignalR need this feature for 8.0.

Author: benjaminpetit
Assignees: -
Labels:

area-Extensions-DependencyInjection

Milestone: -

@steveharter steveharter added this to the 8.0.0 milestone Sep 15, 2023
@benjaminpetit benjaminpetit merged commit 048978a into dotnet:main Sep 15, 2023
@benjaminpetit
Copy link
Member Author

/backport to release/8.0

@github-actions
Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6201381699

@github-actions
Copy link
Contributor

@benjaminpetit an error occurred while backporting to release/8.0, please check the run log for details!

Error: @benjaminpetit is not a repo collaborator, backporting is not allowed. If you're a collaborator please make sure your dotnet team membership visibility is set to Public on https://github.com/orgs/dotnet/people?query=benjaminpetit

@github-actions
Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6201381699

@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.

[FromKeyedServices("keyName")] Keyed services support in Microsoft.Extensions.DependencyInjection is not resolving dependency in constructor

2 participants