Skip to content

Commit 7341bab

Browse files
authored
Updates
1 parent b0c1c37 commit 7341bab

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

aspnetcore/blazor/fundamentals/configuration.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -339,29 +339,39 @@ builder.Services.Configure<OptionsExample>(
339339
builder.Configuration.GetSection("OptionsExample"));
340340
```
341341

342-
To retreive the settings in a class file with the [`[Inject]` attribute](xref:Microsoft.AspNetCore.Components.InjectAttribute):
342+
The following Razor component retrieves the settings with the [`@inject`](xref:mvc/views/razor#inject) directive or [`[Inject]` attribute](xref:Microsoft.AspNetCore.Components.InjectAttribute).
343343

344-
```csharp
345-
using Microsoft.Extensions.Options;
344+
`Options.razor`:
346345

347-
...
346+
```razor
347+
@page "/options"
348+
@using Microsoft.Extensions.Options
349+
@inject IOptions<OptionsExample>? OptionsExample1
348350
349-
[Inject]
350-
public IOptions<OptionsExample>? OptionsExample { get; set; }
351-
```
351+
<h1>Options</h1>
352352
353-
To retrieve the settings in a Razor component with the [`@inject`](xref:mvc/views/razor#inject) directive:
353+
<h2>
354+
&commat;inject approach
355+
</h2>
354356
355-
```razor
356-
@using Microsoft.Extensions.Options
357-
@inject IOptions<OptionsExample>? OptionsExample
357+
<ul>
358+
<li>@OptionsExample1?.Value.Option1</li>
359+
<li>@OptionsExample1?.Value.Option2</li>
360+
</ul>
358361
359-
...
362+
<h2>
363+
[Inject] approach
364+
</h2>
360365
361366
<ul>
362-
<li>@OptionsExample?.Value.Option1</li>
363-
<li>@OptionsExample?.Value.Option2</li>
367+
<li>@OptionsExample2?.Value.Option1</li>
368+
<li>@OptionsExample2?.Value.Option2</li>
364369
</ul>
370+
371+
@code {
372+
[Inject]
373+
public IOptions<OptionsExample>? OptionsExample2 { get; set; }
374+
}
365375
```
366376

367377
Not all of the ASP.NET Core Options features are supported in Razor components. For example, <xref:Microsoft.Extensions.Options.IOptionsSnapshot%601> and <xref:Microsoft.Extensions.Options.IOptionsMonitor%601> 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.

0 commit comments

Comments
 (0)