-
Notifications
You must be signed in to change notification settings - Fork 6k
Add breaking change documentation for FromKeyedServicesAttribute.Key nullability #48778
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
gewarren
merged 4 commits into
main
from
copilot/fix-2b86dfef-db63-43bc-b223-2fb24419f95e
Sep 30, 2025
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
docs/core/compatibility/extensions/8.0/fromkeyedservicesattribute-key-nullable.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: "Breaking change: FromKeyedServicesAttribute.Key can be null" | ||
description: "Learn about the breaking change in .NET 8 where FromKeyedServicesAttribute.Key is now nullable to support unkeyed services and inheritance." | ||
ms.date: 09/29/2025 | ||
ai-usage: ai-assisted | ||
ms.custom: https://dev.azure.com/msft-skilling/Content/_workitems/edit/486863 | ||
--- | ||
|
||
# FromKeyedServicesAttribute.Key can be null | ||
|
||
<xref:Microsoft.Extensions.DependencyInjection.FromKeyedServicesAttribute.Key?displayProperty=nameWithType> has been changed from a non-nullable `object` to a nullable `object?` to support null values for unkeyed services and inheritance scenarios. | ||
|
||
## Version introduced | ||
|
||
.NET 8 | ||
|
||
## Previous behavior | ||
|
||
Previously, <xref:Microsoft.Extensions.DependencyInjection.FromKeyedServicesAttribute.Key?displayProperty=nameWithType> was declared as a non-nullable `object`: | ||
|
||
```csharp | ||
public object Key { get; } | ||
``` | ||
|
||
## New behavior | ||
|
||
Starting in .NET 8, <xref:Microsoft.Extensions.DependencyInjection.FromKeyedServicesAttribute.Key?displayProperty=nameWithType> is now declared as a nullable `object?`: | ||
|
||
```csharp | ||
public object? Key { get; } | ||
``` | ||
|
||
A `null` value indicates there is no key and only the parameter type is used to resolve the service. This is useful for dependency injection implementations that require an explicit way to declare that the parameter should be resolved for unkeyed services. A `null` value is also used with inheritance scenarios to indicate that the key should be inherited from the parent scope. | ||
|
||
## Type of breaking change | ||
|
||
This change can affect [source compatibility](../../categories.md#source-compatibility). | ||
|
||
## Reason for change | ||
|
||
Support was added for keyed services to annotate parameters as unkeyed. This change allows developers to explicitly indicate when a parameter should be resolved without a key, which is particularly useful in scenarios where both keyed and unkeyed services are registered for the same type. | ||
|
||
## Recommended action | ||
|
||
Adjust any code that uses <xref:Microsoft.Extensions.DependencyInjection.FromKeyedServicesAttribute.Key?displayProperty=nameWithType> to handle `null` values. | ||
|
||
## Affected APIs | ||
|
||
- <xref:Microsoft.Extensions.DependencyInjection.FromKeyedServicesAttribute.Key?displayProperty=fullName> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.