Reacting to Configuration changes

This commit is contained in:
Pranav K 2015-09-25 07:51:25 -07:00
parent c4097f8080
commit a3f24bcb1d
6 changed files with 28 additions and 22 deletions

View File

@ -81,7 +81,8 @@ namespace MusicStore.Models
{ {
var appEnv = serviceProvider.GetService<IApplicationEnvironment>(); var appEnv = serviceProvider.GetService<IApplicationEnvironment>();
var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath) var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("config.json") .AddJsonFile("config.json")
.AddEnvironmentVariables(); .AddEnvironmentVariables();
var configuration = builder.Build(); var configuration = builder.Build();

View File

@ -24,7 +24,8 @@ namespace MusicStore
// Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' // Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1'
// is found in both the registered sources, then the later source will win. By this way a Local config // is found in both the registered sources, then the later source will win. By this way a Local config
// can be overridden by a different setting while deployed remotely. // can be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(applicationEnvironment.ApplicationBasePath) var builder = new ConfigurationBuilder()
.SetBasePath(applicationEnvironment.ApplicationBasePath)
.AddJsonFile("config.json") .AddJsonFile("config.json")
//All environment variables in the process's context flow in as configuration values. //All environment variables in the process's context flow in as configuration values.
.AddEnvironmentVariables(); .AddEnvironmentVariables();

View File

@ -41,7 +41,8 @@ namespace MusicStore
// Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' // Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1'
// is found in both the registered sources, then the later source will win. By this way a Local config // is found in both the registered sources, then the later source will win. By this way a Local config
// can be overridden by a different setting while deployed remotely. // can be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(applicationEnvironment.ApplicationBasePath) var builder = new ConfigurationBuilder()
.SetBasePath(applicationEnvironment.ApplicationBasePath)
.AddJsonFile("config.json") .AddJsonFile("config.json")
//All environment variables in the process's context flow in as configuration values. //All environment variables in the process's context flow in as configuration values.
.AddEnvironmentVariables(); .AddEnvironmentVariables();

View File

@ -39,7 +39,8 @@ namespace MusicStore
// Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' // Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1'
// is found in both the registered sources, then the later source will win. By this way a Local config can // is found in both the registered sources, then the later source will win. By this way a Local config can
// be overridden by a different setting while deployed remotely. // be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(env.ApplicationBasePath) var builder = new ConfigurationBuilder()
.SetBasePath(env.ApplicationBasePath)
.AddJsonFile("config.json") .AddJsonFile("config.json")
//All environment variables in the process's context flow in as configuration values. //All environment variables in the process's context flow in as configuration values.
.AddEnvironmentVariables(); .AddEnvironmentVariables();

View File

@ -27,7 +27,8 @@ namespace MusicStore
{ {
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources, //Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
//then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely. //then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(env.ApplicationBasePath) var builder = new ConfigurationBuilder()
.SetBasePath(env.ApplicationBasePath)
.AddJsonFile("config.json") .AddJsonFile("config.json")
.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values. .AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.

View File

@ -31,7 +31,8 @@ namespace MusicStore
{ {
//Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources, //Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
//then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely. //then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
var builder = new ConfigurationBuilder(appEnvironment.ApplicationBasePath) var builder = new ConfigurationBuilder()
.SetBasePath(appEnvironment.ApplicationBasePath)
.AddJsonFile("config.json") .AddJsonFile("config.json")
.AddEnvironmentVariables() //All environment variables in the process's context flow in as configuration values. .AddEnvironmentVariables() //All environment variables in the process's context flow in as configuration values.
.AddJsonFile("configoverride.json", optional: true); // Used to override some configuration parameters that cannot be overridden by environment. .AddJsonFile("configoverride.json", optional: true); // Used to override some configuration parameters that cannot be overridden by environment.