diff --git a/aspnetcore/blazor/fundamentals/configuration.md b/aspnetcore/blazor/fundamentals/configuration.md index 83aa25d22d2b..62fd424799db 100644 --- a/aspnetcore/blazor/fundamentals/configuration.md +++ b/aspnetcore/blazor/fundamentals/configuration.md @@ -315,9 +315,63 @@ For more information on how background updates are handled by PWAs, see ( - builder.Configuration.GetSection("MyOptions")); +builder.Services.Configure( + builder.Configuration.GetSection("OptionsExample")); +``` + +The following Razor component retrieves the settings with the [`@inject`](xref:mvc/views/razor#inject) directive or [`[Inject]` attribute](xref:Microsoft.AspNetCore.Components.InjectAttribute). + +`Options.razor`: + +```razor +@page "/options" +@using Microsoft.Extensions.Options +@inject IOptions? OptionsExample1 + +

Options

+ +

+ @inject approach +

+ +
    +
  • @OptionsExample1?.Value.Option1
  • +
  • @OptionsExample1?.Value.Option2
  • +
+ +

+ [Inject] approach +

+ +
    +
  • @OptionsExample2?.Value.Option1
  • +
  • @OptionsExample2?.Value.Option2
  • +
+ +@code { + [Inject] + public IOptions? OptionsExample2 { get; set; } +} ``` Not all of the ASP.NET Core Options features are supported in Razor components. For example, and configuration is supported, but recomputing option values for these interfaces isn't supported outside of reloading the app by either requesting the app in a new browser tab or selecting the browser's reload button. Merely calling [`StateHasChanged`](xref:blazor/components/lifecycle#state-changes-statehaschanged) doesn't update snapshot or monitored option values when the underlying configuration changes.