Using IRuntimeEnvironment to detect if mono

This commit is contained in:
Praburaj 2015-04-16 15:14:17 -07:00
parent 9c5d86d4c0
commit ecb6184214
4 changed files with 24 additions and 8 deletions

View File

@ -16,13 +16,17 @@ namespace MusicStore
{
public class Startup
{
public Startup(IApplicationEnvironment env)
private readonly IRuntimeEnvironment _runtimeEnvironment;
public Startup(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
{
//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.
Configuration = new Configuration(env.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.
_runtimeEnvironment = runtimeEnvironment;
}
public IConfiguration Configuration { get; private set; }
@ -32,7 +36,7 @@ namespace MusicStore
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
//Sql client not available on mono
var useInMemoryStore = Type.GetType("Mono.Runtime") != null;
var useInMemoryStore = _runtimeEnvironment.RuntimeType.Equals("Mono", StringComparison.OrdinalIgnoreCase);
// Add EF services to the services container
if (useInMemoryStore)

View File

@ -29,13 +29,17 @@ namespace MusicStore
/// </summary>
public class StartupOpenIdConnect
{
public StartupOpenIdConnect(IApplicationEnvironment env)
private readonly IRuntimeEnvironment _runtimeEnvironment;
public StartupOpenIdConnect(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
{
//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.
Configuration = new Configuration(env.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.
_runtimeEnvironment = runtimeEnvironment;
}
public IConfiguration Configuration { get; private set; }
@ -45,7 +49,7 @@ namespace MusicStore
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
//Sql client not available on mono
var useInMemoryStore = Type.GetType("Mono.Runtime") != null;
var useInMemoryStore = _runtimeEnvironment.RuntimeType.Equals("Mono", StringComparison.OrdinalIgnoreCase);
// Add EF services to the services container
if (useInMemoryStore)

View File

@ -19,13 +19,17 @@ namespace MusicStore
{
public class StartupOpenIdConnectTesting
{
public StartupOpenIdConnectTesting(IApplicationEnvironment env)
private readonly IRuntimeEnvironment _runtimeEnvironment;
public StartupOpenIdConnectTesting(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
{
//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.
Configuration = new Configuration(env.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.
_runtimeEnvironment = runtimeEnvironment;
}
public IConfiguration Configuration { get; private set; }
@ -35,7 +39,7 @@ namespace MusicStore
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
//Sql client not available on mono
var useInMemoryStore = Type.GetType("Mono.Runtime") != null;
var useInMemoryStore = _runtimeEnvironment.RuntimeType.Equals("Mono", StringComparison.OrdinalIgnoreCase);
// Add EF services to the services container
if (useInMemoryStore)

View File

@ -25,7 +25,9 @@ namespace MusicStore
{
public class StartupSocialTesting
{
public StartupSocialTesting(IApplicationEnvironment appEnvironment)
private readonly IRuntimeEnvironment _runtimeEnvironment;
public StartupSocialTesting(IApplicationEnvironment appEnvironment, IRuntimeEnvironment runtimeEnvironment)
{
//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.
@ -33,6 +35,8 @@ namespace MusicStore
.AddJsonFile("config.json")
.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.
_runtimeEnvironment = runtimeEnvironment;
}
public IConfiguration Configuration { get; private set; }
@ -45,7 +49,7 @@ namespace MusicStore
string value;
var useInMemoryStore = Configuration.TryGet("UseInMemoryStore", out value) && value == "true" ?
true :
Type.GetType("Mono.Runtime") != null;
_runtimeEnvironment.RuntimeType.Equals("Mono", StringComparison.OrdinalIgnoreCase);
// Add EF services to the services container
if (useInMemoryStore)