-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
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 in IOptions. However, if you do not wrap it in IOptions, 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
Metadata
- ID: 7367a651-2b27-0a57-e7d0-95686cc97f1c
- Service: aspnet-core
- Sub-service: blazor
Metadata
Metadata
Assignees
Labels
Type
Projects
Status