In CreateDefaultBuilder
a call is made to ConfigureAppConfiguration
with some defaults. I'd like to override (or append) to these defaults. I've tried copying CreateDefaultBuilder
into my own function and editing the appropriate lines, however it can't resolve a type used in the function because the type is internal
to AspNetCore namespaces (specifically the HostFilteringStartupFilter
type).
Is there some cleaner way for me to modify the CreateDefaultBuilder
functionality?
EDIT: So I just looked at the source of HostFilteringStartupFilter
and it just calls UseHostFiltering
on the IApplicationBuilder
, so I just added that to my Startup.Configure
but I would still like a cleaner approach if possible..
CreateDefaultBuilder()Initializes a new instance of the WebHostBuilder class with pre-configured defaults.
Application configuration in ASP.NET Core is performed using one or more configuration providers. Configuration providers read configuration data from key-value pairs using a variety of configuration sources: Settings files, such as appsettings. json.
In the upper-left corner of the home page, select Create a resource. In the Search services and marketplace box, enter App Configuration and select Enter. Select App Configuration from the search results, and then select Create. Select the Azure subscription that you want to use to test App Configuration.
CreateDefaultBuilder sets up reasonable defaults that you want to preserve except the configuration part. CreateDefaultBuilder performs the following configuration setup:
Knowing this default layering, the fact that every layer can potentially override values in previous ones and the fact that you can only add configuration providers to the list (while not being able to remove them), you can now solve your problem.
Overriding configuration on top of CreateDefaultBuilder is done using ConfigureAppConfiguration :
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
// Override here specifying new or previous layers to make sure
// you get the desired outcome.
// e.g. If you specify your appsettings.json you basically start from scratch
...
})...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With