-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add BindConfiguration extension method for OptionsBuilder #39825
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
@maryamariyan, @davidfowl, maybe we should discuss this behaviour? Should I maybe throw |
|
I also wanted to add test-cases for this new API, but I realized after some searching that the |
...soft.Extensions.Options.ConfigurationExtensions/src/OptionsBuilderConfigurationExtensions.cs
Outdated
Show resolved
Hide resolved
|
Tagging subscribers to this area: @maryamariyan |
....Options.ConfigurationExtensions/ref/Microsoft.Extensions.Options.ConfigurationExtensions.cs
Outdated
Show resolved
Hide resolved
|
@fredrikhr are you adding tests for coverage of this API as well? Perhaps you could add them in https://github.com/dotnet/runtime/blob/master/src/libraries/Microsoft.Extensions.Options/tests/OptionsBuilderTest.cs Ideally though, if you could add a new test project for Microsoft.Extensions.Options.ConfigurationExtensions and place your tests there it would be better. Because if the test class was under but for now since all Options tests are under |
...soft.Extensions.Options.ConfigurationExtensions/src/OptionsBuilderConfigurationExtensions.cs
Outdated
Show resolved
Hide resolved
3315cf1 to
b9628cc
Compare
|
@maryamariyan I'll start working on a new unit testing projects and add tests. |
|
@maryamariyan okay I have added a new Unit test project for MS.Ext.Options.ConfigExt can you look at if what I did is okay? I took inspiration from how the unit test project for MS.Ext.Options work. For the new API I also enabled nullable annotations using |
92871b7 to
6f07962
Compare
6f07962 to
5906895
Compare
I think it's better to add the API without nullable annotations. They would get covered once the entire assembly is annotated. It could make it harder to review later otherwise. |
…ethod" This reverts commit 14598c1.
|
@maryamariyan okay your call :) |
maryamariyan
left a comment
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.
LGTM thanks @fredrikhr.
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{3EFE3DA9-F864-40A3-8892-899D731CC027}" | ||
| EndProject | ||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dependencies", "dependencies", "{78CAAC57-641E-4EBC-AD1F-0AA1034C94A2}" |
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.
Nit: just making a quick comparison style-wise with other sln files in the repo, and we don't seem to have "dependencies" like what you are adding here. e.g. Primitives.
Thanks for adding the test project!
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.
Okay, I removed the dependencies solution folder and moved all together into test. ddb583b
|
@davidfowl @HaoK seems like your feedback are addressed as well. |
|
Thanks @fredrikhr |
|
@maryamariyan merged into |
sure thing :) |
|
I think we missed wiring up change notifications as part of this change 😢 |
Implements new API proposed in #36209. The proposal was reviewed and approved by @terrajobst on
2020-07-21T18:33:00Z, ref.: #36209 (comment).Details
The method calls the
Configure<TDep>method on the passedoptionsBuilderinstance, specifyingIConfigurationas an injected dependency.The
configureOptionsargument for the call to theConfiguremethod is given as a lambda that accepts theIConfigurationroot instance from DI. The lambda is now responsible for extracting the appropriate section from that root. This is done byconfigSectionPathis a non-empty string,IConfiguration.GetSectionis called withconfigSectionPathas the argument.configSectionPathisnullor an empty string, theNameproperty of theoptionsBuilderparameter is used.nullor empty.When the appropriate configuration section has been obtained, the
Bindextension method is called, perfoming the binding agrainst theTOptionsinstance. TheconfigureBinderparameter is specified as nullable, and is passed directly to theBindextension method. According to the current implementation ofConfigurationBinder.Bind,nullis an acceptable value.Returns
The method returns the value of the
optionsBuilderthis-parameter to allow for fluid chained method calls.Exceptions
optionsBuilderisnullthe method immediately throws a newArgumentNullException.fixes #36209, duplicate of dotnet/extensions#3020 and #34191