Using IRuntimeEnvironment to detect if mono
This commit is contained in:
parent
9c5d86d4c0
commit
ecb6184214
|
|
@ -16,13 +16,17 @@ namespace MusicStore
|
||||||
{
|
{
|
||||||
public class Startup
|
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,
|
//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(env.ApplicationBasePath)
|
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.
|
||||||
|
|
||||||
|
_runtimeEnvironment = runtimeEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; private set; }
|
public IConfiguration Configuration { get; private set; }
|
||||||
|
|
@ -32,7 +36,7 @@ namespace MusicStore
|
||||||
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
||||||
|
|
||||||
//Sql client not available on mono
|
//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
|
// Add EF services to the services container
|
||||||
if (useInMemoryStore)
|
if (useInMemoryStore)
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,17 @@ namespace MusicStore
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class StartupOpenIdConnect
|
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,
|
//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(env.ApplicationBasePath)
|
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.
|
||||||
|
|
||||||
|
_runtimeEnvironment = runtimeEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; private set; }
|
public IConfiguration Configuration { get; private set; }
|
||||||
|
|
@ -45,7 +49,7 @@ namespace MusicStore
|
||||||
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
||||||
|
|
||||||
//Sql client not available on mono
|
//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
|
// Add EF services to the services container
|
||||||
if (useInMemoryStore)
|
if (useInMemoryStore)
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,17 @@ namespace MusicStore
|
||||||
{
|
{
|
||||||
public class StartupOpenIdConnectTesting
|
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,
|
//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(env.ApplicationBasePath)
|
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.
|
||||||
|
|
||||||
|
_runtimeEnvironment = runtimeEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; private set; }
|
public IConfiguration Configuration { get; private set; }
|
||||||
|
|
@ -35,7 +39,7 @@ namespace MusicStore
|
||||||
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
||||||
|
|
||||||
//Sql client not available on mono
|
//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
|
// Add EF services to the services container
|
||||||
if (useInMemoryStore)
|
if (useInMemoryStore)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ namespace MusicStore
|
||||||
{
|
{
|
||||||
public class StartupSocialTesting
|
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,
|
//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.
|
||||||
|
|
@ -33,6 +35,8 @@ namespace MusicStore
|
||||||
.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.
|
||||||
|
|
||||||
|
_runtimeEnvironment = runtimeEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; private set; }
|
public IConfiguration Configuration { get; private set; }
|
||||||
|
|
@ -45,7 +49,7 @@ namespace MusicStore
|
||||||
string value;
|
string value;
|
||||||
var useInMemoryStore = Configuration.TryGet("UseInMemoryStore", out value) && value == "true" ?
|
var useInMemoryStore = Configuration.TryGet("UseInMemoryStore", out value) && value == "true" ?
|
||||||
true :
|
true :
|
||||||
Type.GetType("Mono.Runtime") != null;
|
_runtimeEnvironment.RuntimeType.Equals("Mono", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
// Add EF services to the services container
|
// Add EF services to the services container
|
||||||
if (useInMemoryStore)
|
if (useInMemoryStore)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue