Reputation: 39058
According to some wise source, there's a method called AddJsonFile for reading in a config file. One of its signatures allows to specify optional and reloadOnChange.
IConfigurationRoot config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("config.json", false, false)
.Build();
However, I can't find info on what's the default value for that in case I use a signature without those explicitly specified. I can assume that it's false, basing it on the fact that it's the default value of a boolean (i.e. default(bool) is false).
But I prefer to have stuff explicitly and linkably stated.
Upvotes: 5
Views: 4480
Reputation: 5624
Refer the source code present at: https://github.com/aspnet/Configuration/blob/master/src/Config.Json/JsonConfigurationExtensions.cs
As per this, if you dont provide parameters they are false. Please note below method:
/// <summary>
/// Adds the JSON configuration provider at <paramref name="path"/> to <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="path">Path relative to the base path stored in
/// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddJsonFile(this IConfigurationBuilder builder, string path)
{
return AddJsonFile(builder, provider: null, path: path, optional: false, reloadOnChange: false);
}
}
As you mentioned earlier in the question, you can use another overload of this method to set reloadOnChange value. Below is sample code from MSDN:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false);
config.AddCommandLine(args);
})
.UseStartup<Startup>();
}
Upvotes: 9