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

Add extension methods for creating OptionsBuilder with ValidateOnStart support #89973

Merged
merged 2 commits into from
Aug 9, 2023

Conversation

steveharter
Copy link
Member

Fixes #89263

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Aug 3, 2023

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

Issue Details

Fixes #89263

Author: steveharter
Assignees: steveharter
Labels:

area-Extensions-Options

Milestone: 8.0.0

@tarekgh
Copy link
Member

tarekgh commented Aug 3, 2023

CC @halter73

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.

LGTM.

@tarekgh
Copy link
Member

tarekgh commented Aug 3, 2023

CC @ericstj

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

We technically approved adding this to OptionsBuilderExtensions instead of OptionsServiceCollectionExtensions in API review for some reason, but OptionsServiceCollectionExtensions is the correct place.

string? name = null)
where TOptions : class
{
return new OptionsBuilder<TOptions>(services, name ?? Options.Options.DefaultName).ValidateOnStart();
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this call AddOptions? I think neither the OptionsBuilder constructor nor ValidateOnStart do this.

Suggested change
return new OptionsBuilder<TOptions>(services, name ?? Options.Options.DefaultName).ValidateOnStart();
services.AddOptions();
return new OptionsBuilder<TOptions>(services, name ?? Options.Options.DefaultName).ValidateOnStart();

Copy link
Member Author

@steveharter steveharter Aug 9, 2023

Choose a reason for hiding this comment

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

ValidateOnStart() does call optionsBuilder.Services.AddOptions<StartupValidatorOptions>() which calls services.AddOptions();

@steveharter steveharter merged commit c999608 into dotnet:main Aug 9, 2023
101 of 103 checks passed
@steveharter steveharter deleted the OptionsBuilderExt branch August 9, 2023 14:58
/// <param name="name">The name of the options instance.</param>
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
public static OptionsBuilder<TOptions> AddOptionsWithValidateOnStart<
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TOptions,
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to be .All? Shouldn't it be

[DynamicallyAccessedMembers(Options.DynamicallyAccessedMembers)] TOptions,

?

Copy link
Member

Choose a reason for hiding this comment

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

The same question for the other overload as well. I believe it should be:

public static OptionsBuilder<TOptions> AddOptionsWithValidateOnStart<
            [DynamicallyAccessedMembers(Options.DynamicallyAccessedMembers)] TOptions>(
            this IServiceCollection services,
            string? name = null)

@ghost ghost locked as resolved and limited conversation to collaborators Sep 8, 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.

[API Proposal]: Add extensions to create an OptionsBuilder with ValidateOnStart support
5 participants