dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.59k stars 25.29k forks source link

`TOptions` instance is validated when `IOptions<TOptions>.Value` is accessed #33837

Open bravequickcleverfibreyarn opened 3 days ago

bravequickcleverfibreyarn commented 3 days ago

Description

From https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-8.0#validateonstart

Options validation runs the first time an IOptions<TOptions>, IOptionsSnapshot<TOptions>, or IOptionsMonitor<TOptions> implementation is created.

Options validation runs when IOptions<TOptions>.Value is accessed not when IOptions<TOptions> is created. Similar applies for IOptionsSnapshot<TOptions> & IOptionsMonitor<TOptions>. See also https://source.dot.net/#Microsoft.Extensions.Options/OptionsFactory.cs,55.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/configuration/options.md

Document ID

dc7e3449-650b-d117-5eac-69e5ccb250cb

Article author

@tdykstra

tdykstra commented 3 days ago

Thanks for reporting that. We'll revise the wording the next time we update the article, or you're welcome to submit a Pull Request to address the issue.

bravequickcleverfibreyarn commented 2 days ago

I picked the latter – https://github.com/dotnet/AspNetCore.Docs/pull/33844. Please, redact this. On my local env it is impossible to validate code references and I am not familiar with project technical writers' customs.

tdykstra commented 2 days ago

Thanks for the PR, I'll fix the xref links, probably Monday.