Skip to content

Fix missing ServiceCallSite.Key causing an unkeyed cache entry to be overwritten by a keyed instance #113343

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

Merged

Conversation

IliaShuliatikov
Copy link
Contributor

Fix missing ServiceCallSite.Key causing an unkeyed cache entry to be overwritten by a keyed instance when using DynamicServiceProviderEngine and cover all cases (Generic (TryCreateOpenGeneric) and Enumerable (TryCreateEnumerable) and the basic one (TryCreateExact) ) with unit tests.

Fixes #111795

@KalleOlaviNiemitalo
Copy link

I feel that ServiceProviderExtensionsTest might not be the best class to contain the new tests, because they are intended to test the service container itself rather than the extension methods.

@steveharter
Copy link
Member

I feel that ServiceProviderExtensionsTest might not be the best class to contain the new tests, because they are intended to test the service container itself rather than the extension methods.

Perhaps the class CallSiteTests in file CallSiteTests.cs would be a better match?

@IliaShuliatikov
Copy link
Contributor Author

IliaShuliatikov commented Mar 14, 2025

@KalleOlaviNiemitalo, @steveharter, that's a good point, thanks.

I moved the new tests to the CallSiteTests class, made them more specific to ServiceCallSite and removed unnecessary dependency on DynamicServiceProviderEngine, please take a look.

Copy link
Member

@steveharter steveharter left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this.

@steveharter steveharter merged commit 23e0798 into dotnet:main Mar 14, 2025
81 of 84 checks passed
@IliaShuliatikov
Copy link
Contributor Author

Glad I could help and make .NET a bit better!

@IliaShuliatikov IliaShuliatikov deleted the fix-missing-servicecallsite-key branch March 14, 2025 19:31
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-DependencyInjection community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ServiceProvider.GetServices() Returns Results Based on Last GetKeyedServices() Call
3 participants