Refactor configuration to take advantage of Options Pattern
See original GitHub issueCurrent .NET Core configuration utilizes a non-conventional pattern to load configuration values.
ASP.NET Core already has an established pattern to load options. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-3.1
There are several advantages to using this pattern.
- It’s common convention. No surprises for future contributors.
- It allows options monitoring and dynamic reloading when required.
- It negates the requirement for each superfluous interface definition and implementation.
Binding a section becomes trivial.
services.Configure<MyOptions>(Configuration.GetSection(nameof(MyOptions)));
Consuming it equally so.
public class MyOptionsConsumer(IOptions<MyOptions> options)
{
Guard.NotNull(options, nameof(options));
this.options = options.Value;
}
Unit testing again is trivial.
var myOptions = new MyOptions();
var myOptionsConsumer = new MyOptionsConsumer(Options.Create(myOptions));
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Options pattern in ASP.NET Core
The options pattern uses classes to provide strongly typed access to groups of related settings. When configuration settings are isolated by ...
Read more >Strongly Typed Configurations with Options Pattern
The options pattern uses classes to provide strongly typed access to groups of related settings. The Options pattern adheres to the following ...
Read more >ASP.NET Core Configuration – Options Pattern
The options pattern gives us similar possibilities, but it offers a more structured approach and more features like validation, live reloading, ...
Read more >ASP.NET Core - Accessing Configurations Using Options ...
The main advantage of options pattern is that we create classes and each class which will have properties for configuring the specific parts ......
Read more >The Options pattern | An Atypical ASP.NET Core 6 Design ...
The Options pattern's goal is to use settings at runtime, allowing changes to the application to happen without changing the code. The settings...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can we/should we close this now @bergmania? Seems that any further uses of
IOptions
will come in as and when new features are migrated, rather than being a separate task to add.We decide to allow the MS Config interfaces in
Umbraco.Core
. @AndyButland already started a draft PR. Good start, and we can continue on work.I think we should make a
netcore/config
branch as the base branch for all these smaller config PRs, so we can merge these intonetcore/netcore
as one big PR, but review it as several smaller PRs.