Use the in memory store on the Nano server
This commit is contained in:
parent
8c9969ed3f
commit
63038b7278
|
|
@ -0,0 +1,77 @@
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Microsoft.Framework.Runtime;
|
||||||
|
using Microsoft.Framework.Runtime.Infrastructure;
|
||||||
|
|
||||||
|
namespace MusicStore
|
||||||
|
{
|
||||||
|
internal class Platform
|
||||||
|
{
|
||||||
|
// Defined in winnt.h
|
||||||
|
private const int PRODUCT_NANO_SERVER = 0x0000006D;
|
||||||
|
|
||||||
|
[DllImport("api-ms-win-core-sysinfo-l1-2-1.dll", SetLastError = false)]
|
||||||
|
private static extern bool GetProductInfo(
|
||||||
|
int dwOSMajorVersion,
|
||||||
|
int dwOSMinorVersion,
|
||||||
|
int dwSpMajorVersion,
|
||||||
|
int dwSpMinorVersion,
|
||||||
|
out int pdwReturnedProductType);
|
||||||
|
|
||||||
|
private readonly IRuntimeEnvironment _runtimeEnvironment;
|
||||||
|
|
||||||
|
private bool? _isNano;
|
||||||
|
private bool? _isMono;
|
||||||
|
|
||||||
|
public Platform(IRuntimeEnvironment runtimeEnvironment)
|
||||||
|
{
|
||||||
|
_runtimeEnvironment = runtimeEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsRunningOnMono
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_isMono == null)
|
||||||
|
{
|
||||||
|
_isMono = _runtimeEnvironment.RuntimeType.Equals("Mono", StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _isMono.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsRunningOnNanoServer
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_isNano == null)
|
||||||
|
{
|
||||||
|
var osVersion = new Version(_runtimeEnvironment.OperatingSystemVersion);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int productType;
|
||||||
|
if (GetProductInfo(osVersion.Major, osVersion.Minor, 0,0, out productType))
|
||||||
|
{
|
||||||
|
_isNano = productType == PRODUCT_NANO_SERVER;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_isNano = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// If the API call fails, the API set is not there which means
|
||||||
|
// that we are definetely not running on Nano
|
||||||
|
_isNano = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _isNano.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,7 +17,7 @@ namespace MusicStore
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
private readonly IRuntimeEnvironment _runtimeEnvironment;
|
private readonly Platform _platform;
|
||||||
|
|
||||||
public Startup(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
|
public Startup(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
|
||||||
{
|
{
|
||||||
|
|
@ -27,7 +27,7 @@ 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.
|
||||||
|
|
||||||
_runtimeEnvironment = runtimeEnvironment;
|
_platform = new Platform(runtimeEnvironment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; private set; }
|
public IConfiguration Configuration { get; private set; }
|
||||||
|
|
@ -36,8 +36,7 @@ namespace MusicStore
|
||||||
{
|
{
|
||||||
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
||||||
|
|
||||||
//Sql client not available on mono
|
var useInMemoryStore = _platform.IsRunningOnMono || _platform.IsRunningOnNanoServer;
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace MusicStore
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class StartupOpenIdConnect
|
public class StartupOpenIdConnect
|
||||||
{
|
{
|
||||||
private readonly IRuntimeEnvironment _runtimeEnvironment;
|
private readonly Platform _platform;
|
||||||
|
|
||||||
public StartupOpenIdConnect(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
|
public StartupOpenIdConnect(IApplicationEnvironment env, IRuntimeEnvironment runtimeEnvironment)
|
||||||
{
|
{
|
||||||
|
|
@ -40,7 +40,7 @@ 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.
|
||||||
|
|
||||||
_runtimeEnvironment = runtimeEnvironment;
|
_platform = new Platform(runtimeEnvironment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; private set; }
|
public IConfiguration Configuration { get; private set; }
|
||||||
|
|
@ -49,8 +49,7 @@ namespace MusicStore
|
||||||
{
|
{
|
||||||
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
|
||||||
|
|
||||||
//Sql client not available on mono
|
var useInMemoryStore = _platform.IsRunningOnMono || _platform.IsRunningOnNanoServer;
|
||||||
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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue