From ecb61842143a68068463100156f4d98aa6e1361d Mon Sep 17 00:00:00 2001 From: Praburaj Date: Thu, 16 Apr 2015 15:14:17 -0700 Subject: [PATCH] Using IRuntimeEnvironment to detect if mono --- src/MusicStore/Startup.cs | 8 ++++++-- src/MusicStore/StartupOpenIdConnect.cs | 8 ++++++-- .../compiler/shared/Mocks/StartupOpenIdConnectTesting.cs | 8 ++++++-- .../compiler/shared/Mocks/StartupSocialTesting.cs | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 2f1215786f..4cd38a8bd1 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -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(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) diff --git a/src/MusicStore/StartupOpenIdConnect.cs b/src/MusicStore/StartupOpenIdConnect.cs index 7e9d5b2cab..6a9e43f305 100644 --- a/src/MusicStore/StartupOpenIdConnect.cs +++ b/src/MusicStore/StartupOpenIdConnect.cs @@ -29,13 +29,17 @@ namespace MusicStore /// 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(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) diff --git a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs index 806e3628a7..b8573b7736 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupOpenIdConnectTesting.cs @@ -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(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) diff --git a/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs index b2c34bfcac..60a5f23e16 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs @@ -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)