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

Clarify null name for IOptions related types #10038

Merged
merged 2 commits into from
Jun 24, 2024

Conversation

kevincathcart-cas
Copy link
Contributor

Summary

Fixes some really poor wording related to passing null to Get(string? name) methods of IOptions related types.

Was:

The name of the TOptions instance, if Microsoft.Extensions.Options.Options.DefaultName is null.

But that makes no sense. DefaultName is public static readonly string DefaultName = string.Empty; and cannot be null. The actual intention is to document that these types use the value of DefaultName if null is passed.

Now:

The name of the TOptions instance. Uses Microsoft.Extensions.Options.Options.DefaultName if null is provided.

That is accurate and contractual. Unnamed options use DefaultName for their name, as documented in many places in these docs, and passing null here is explicitly requesting that the unnamed version of the option is returned, which happens by using DefaultName. Any alternate implementation of the interfaces in question that distinguished between null and DefaultName, would be non-conforming and incompatible since apps can freely choose to pass null or DefaultName, and don't expect any difference between the two.

@kevincathcart-cas kevincathcart-cas requested a review from a team as a code owner June 18, 2024 18:09
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 18, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 18, 2024
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

1 similar comment
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

Copy link

Learn Build status updates of commit cdd065e:

✅ Validation status: passed

File Status Preview URL Details
xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml ✅Succeeded View
xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml ✅Succeeded View
xml/Microsoft.Extensions.Options/OptionsManager`1.xml ✅Succeeded View
xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-options

Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

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

@kevincathcart-cas thanks for helping with the doc clarification. LGTM.

Should we add something telling Microsoft.Extensions.Options.Options.DefaultName is empty string too? This may help users to understand what name value they will get.

CC @gewarren

@gewarren gewarren removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 20, 2024
xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml Outdated Show resolved Hide resolved
xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml Outdated Show resolved Hide resolved
xml/Microsoft.Extensions.Options/OptionsManager`1.xml Outdated Show resolved Hide resolved
xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml Outdated Show resolved Hide resolved
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Copy link

Learn Build status updates of commit 15f926f:

✅ Validation status: passed

File Status Preview URL Details
xml/Microsoft.Extensions.Options/IOptionsMonitor`1.xml ✅Succeeded View
xml/Microsoft.Extensions.Options/IOptionsSnapshot`1.xml ✅Succeeded View
xml/Microsoft.Extensions.Options/OptionsManager`1.xml ✅Succeeded View
xml/Microsoft.Extensions.Options/OptionsMonitor`1.xml ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

@tarekgh tarekgh merged commit 8711385 into dotnet:main Jun 24, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Extensions-Options 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.

None yet

3 participants