-
Notifications
You must be signed in to change notification settings - Fork 5.3k
ServiceKey comparisons use Equals for matching #95807
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
Conversation
This brings RemoveAllKeyed in line with service resolution (ServiceProvider.GetRequiredKeyedService)
|
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue DetailsFix #95754 I assume here that the issue (currently untriaged) is confirmed as a bug. Based on documentation: https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection#keyed-services
Also based on comparison for resolving in public bool Equals(ServiceIdentifier other)
{
if (ServiceKey == null && other.ServiceKey == null)
{
return ServiceType == other.ServiceType;
}
else if (ServiceKey != null && other.ServiceKey != null)
{
return ServiceType == other.ServiceType && ServiceKey.Equals(other.ServiceKey);
}
return false;
}
|
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.
Thank you! This looks like a simple fix to the keyed TryAddEnumerable/Remove/Replace service collection extensions. Thanks for added the regression tests too.
I think we should backport this for .NET 8 patching.
|
/azp run |
|
You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list. |
|
/azp run runtime |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/backport to release/8.0-staging |
|
Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/7491216853 |
This change avoids TryAddEnumerable_DoesNotAddDuplicate giving false negative (passing test when it should fail) due to match on ReferenceEquals. Delete 2 tests that were added in dotnet#95807 due to this weakness in `TryAddEnumerable_DoesNotAddDuplicate`
Fix #95754
I assume here that the issue (currently untriaged) is confirmed as a bug.
Based on documentation: https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection#keyed-services
Also based on comparison for resolving in
ServiceProvider.GetRequiredKeyedService.That is implemented in
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceIdentifier