Add Example of using a SettingsOptions in Blazor #34458
Labels
aspnet-core/svc
blazor/subsvc
Blazor
doc-enhancement
Pri2
Source - Docs.ms
Docs Customer feedback via GitHub Issue
Description
In the example of "Options configuration", it gives an example of how to add it to the configuration:
builder.Services.Configure<MyOptions>( builder.Configuration.GetSection("MyOptions"));
However, it does not give an example of how to retrieve the settings. In other words, in your page, how do you access the MySettings when you need to access the actual settings?
This is what should be added;
[Inject] public IOptions<MyOptions> MyOptions { get; set; }
The reason this is useful is that it is non-obvious that
MyOptions
needs to be wrapped inIOptions
. However, if you do not wrap it inIOptions
, then it will not be injected. I think adding this would be helpful.Page URL
https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/configuration?view=aspnetcore-9.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/fundamentals/configuration.md
Document ID
8c769648-728d-72ce-ebf6-2a06e5076aa2
Article author
@guardrex
Metadata
Related Issues
The text was updated successfully, but these errors were encountered: