Allow Use of IConfigureOptions Consistently Everywhere
See original GitHub issueIs your feature request related to a problem? Please describe.
IConfigureOptions<T>
allows you to move your configuration code to a separate class. However, it cannot be used with certain API’s which require us to pass an Action<T>
:
IServiceCollection AddStackExchangeRedisCache(this IServiceCollection services, Action<RedisCacheOptions> setupAction)
IServiceCollection AddHsts(this IServiceCollection services, Action<HstsOptions> configureOptions)
This is not an exhaustive list, there may be others.
Describe the solution you’d like
All API’s in ASP.NET Core should be consistent and allow us to configure them using IConfigureOptions<T>
. The following overloads should be added:
IServiceCollection AddStackExchangeRedisCache(this IServiceCollection services)
IServiceCollection AddHsts(this IServiceCollection services)
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
The dangers and gotchas of using scoped services in ...
In this post I look at the problems you can hit with strongly-typed settings when you inject Scoped services into IConfigureOptions, ...
Read more >How to configure options sometime later at runtime?
Reconfiguring options using IServiceCollection.Configure is not possible after initialization because BuildServiceProvider has already been ...
Read more >Validated Strongly Typed IOptions - Kaylumah
The HostConfiguration is used to set variables like the DOTNET_ENVIRONMENT , which is used to load the proper appsettings.json and user secrets.
Read more >Options pattern in ASP.NET Core
Discover how to use the options pattern to represent groups of related settings in ASP.NET Core apps.
Read more >The Options pattern | An Atypical ASP.NET Core 6 Design ...
The Options pattern in ASP.NET Core allows us to seamlessly load settings from multiple sources. We can customize these sources when creating IHostBuilder...
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
API review:
configureOptions
in the above example can be allowed to be soft-allow null values (i.e. not perform null checks) for the sake of brevity of implementation.Configure???
as the name for the method e.g.ConfigureMyFeatureOptions(Action<MyFeatureOptions> configureOptions)
whereconfigureOptions
is non-null.Separately we’ll approve the changes proposed in this issue:
API Review Notes:
We are worried that adding the non-options-configuring
AddStackExchangeRedisCache(this IServiceCollection services)
will create too much confusion by making people think configuring options isn’t necessary. If options are configured seperately, callingAddStackExchangeRedisCache(this IServiceCollection services, Action<RedisCacheOptions> configure)
with_ => { }
is easy enough.