Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Example of using a SettingsOptions in Blazor #34458

Open
gregoryagu opened this issue Jan 9, 2025 · 2 comments · May be fixed by #34459
Open

Add Example of using a SettingsOptions in Blazor #34458

gregoryagu opened this issue Jan 9, 2025 · 2 comments · May be fixed by #34459

Comments

@gregoryagu
Copy link

gregoryagu commented Jan 9, 2025

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

@guardrex

Metadata

  • ID: 7367a651-2b27-0a57-e7d0-95686cc97f1c
  • Service: aspnet-core
  • Sub-service: blazor

Related Issues

Copy link
Contributor

github-actions bot commented Jan 9, 2025

💃🕺🥳 Happy New Year! 🎈🎆🍾🥂🎉

Stand-by! ... A green dinosaur 🦖 will be along shortly to assist.

@guardrex
Copy link
Collaborator

guardrex commented Jan 9, 2025

Thanks, @gregoryagu ... I'll schedule this.

@guardrex guardrex moved this from Triage to P2 - Medium Priority in Blazor.Docs Jan 9, 2025
@guardrex guardrex moved this from P2 - Medium Priority to In progress in Blazor.Docs Jan 9, 2025
@guardrex guardrex linked a pull request Jan 9, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

Successfully merging a pull request may close this issue.

2 participants