Use InMemoryStore if the sample is being run on Mono
Detecting if the application is running on mono and using InMemoryStore instead of SqlServer.
This commit is contained in:
parent
863888bfb4
commit
b440d4ff66
|
|
@ -26,9 +26,20 @@ namespace MusicStore
|
|||
|
||||
app.UseServices(services =>
|
||||
{
|
||||
//If this type is present - we're on mono
|
||||
var runningOnMono = Type.GetType("Mono.Runtime") != null;
|
||||
|
||||
// Add EF services to the services container
|
||||
services.AddEntityFramework()
|
||||
.AddSqlServer();
|
||||
if (runningOnMono)
|
||||
{
|
||||
services.AddEntityFramework()
|
||||
.AddInMemoryStore();
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddEntityFramework()
|
||||
.AddSqlServer();
|
||||
}
|
||||
|
||||
services.AddScoped<MusicStoreContext>();
|
||||
|
||||
|
|
@ -37,7 +48,14 @@ namespace MusicStore
|
|||
{
|
||||
options.DefaultAdminUserName = configuration.Get("DefaultAdminUsername");
|
||||
options.DefaultAdminPassword = configuration.Get("DefaultAdminPassword");
|
||||
options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
|
||||
if (runningOnMono)
|
||||
{
|
||||
options.UseInMemoryStore();
|
||||
}
|
||||
else
|
||||
{
|
||||
options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
|
||||
}
|
||||
});
|
||||
|
||||
// Add Identity services to the services container
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
"Microsoft.AspNet.Security.Cookies": "1.0.0-*",
|
||||
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
|
||||
"EntityFramework.SqlServer": "7.0.0-*",
|
||||
/*For Mono*/
|
||||
"EntityFramework.InMemory": "7.0.0-*",
|
||||
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*",
|
||||
"Microsoft.Framework.OptionsModel": "1.0.0-*"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue