React to configuration model change

This commit is contained in:
Troy Dai 2015-04-10 11:42:23 -07:00
parent 25a68f9f79
commit dcac97fe3b
7 changed files with 20 additions and 13 deletions

View File

@ -5,17 +5,17 @@ using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Runtime;
using MusicStore.Apis; using MusicStore.Apis;
using MusicStore.Models; using MusicStore.Models;
namespace MusicStore.Spa namespace MusicStore.Spa
{ {
public class Startup public class Startup
{ {
public Startup() public Startup(IApplicationEnvironment env)
{ {
Configuration = new Configuration() Configuration = new Configuration(env.ApplicationBasePath)
.AddJsonFile("Config.json") .AddJsonFile("Config.json")
.AddEnvironmentVariables(); .AddEnvironmentVariables();
} }

View File

@ -8,6 +8,7 @@ using Microsoft.Data.Entity;
using Microsoft.Data.Entity.SqlServer; using Microsoft.Data.Entity.SqlServer;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Runtime;
namespace MusicStore.Models namespace MusicStore.Models
{ {
@ -86,7 +87,9 @@ namespace MusicStore.Models
/// <returns></returns> /// <returns></returns>
private static async Task CreateAdminUser(IServiceProvider serviceProvider) private static async Task CreateAdminUser(IServiceProvider serviceProvider)
{ {
var configuration = new Configuration() var appEnv = serviceProvider.GetService<IApplicationEnvironment>();
var configuration = new Configuration(appEnv.ApplicationBasePath)
.AddJsonFile("config.json") .AddJsonFile("config.json")
.AddEnvironmentVariables(); .AddEnvironmentVariables();

View File

@ -9,17 +9,18 @@ using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Microsoft.Framework.Runtime;
using MusicStore.Models; using MusicStore.Models;
namespace MusicStore namespace MusicStore
{ {
public class Startup public class Startup
{ {
public Startup() public Startup(IApplicationEnvironment env)
{ {
//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.
Configuration = new Configuration() Configuration = new Configuration(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

@ -10,6 +10,7 @@ using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Microsoft.Framework.Runtime;
using Microsoft.Net.Http.Server; using Microsoft.Net.Http.Server;
using MusicStore.Models; using MusicStore.Models;
@ -30,11 +31,11 @@ namespace MusicStore
/// </summary> /// </summary>
public class StartupNtlmAuthentication public class StartupNtlmAuthentication
{ {
public StartupNtlmAuthentication() public StartupNtlmAuthentication(IApplicationEnvironment env)
{ {
//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.
Configuration = new Configuration() Configuration = new Configuration(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

@ -9,6 +9,7 @@ using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Microsoft.Framework.Runtime;
using MusicStore.Models; using MusicStore.Models;
namespace MusicStore namespace MusicStore
@ -28,11 +29,11 @@ namespace MusicStore
/// </summary> /// </summary>
public class StartupOpenIdConnect public class StartupOpenIdConnect
{ {
public StartupOpenIdConnect() public StartupOpenIdConnect(IApplicationEnvironment env)
{ {
//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.
Configuration = new Configuration() Configuration = new Configuration(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

@ -10,6 +10,7 @@ using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Microsoft.Framework.Runtime;
using MusicStore.Mocks.Common; using MusicStore.Mocks.Common;
using MusicStore.Mocks.OpenIdConnect; using MusicStore.Mocks.OpenIdConnect;
using MusicStore.Models; using MusicStore.Models;
@ -18,11 +19,11 @@ namespace MusicStore
{ {
public class StartupOpenIdConnectTesting public class StartupOpenIdConnectTesting
{ {
public StartupOpenIdConnectTesting() public StartupOpenIdConnectTesting(IApplicationEnvironment env)
{ {
//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.
Configuration = new Configuration() Configuration = new Configuration(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

@ -29,7 +29,7 @@ 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.
Configuration = new Configuration() Configuration = new Configuration(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.