|
|
|
@ -1,11 +1,12 @@ |
|
|
|
using System; |
|
|
|
using Microsoft.Data.Sqlite; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure; |
|
|
|
using Microsoft.EntityFrameworkCore.Storage; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
|
using Volo.Abp.Identity.EntityFrameworkCore; |
|
|
|
using Volo.Abp.IdentityServer.EntityFrameworkCore; |
|
|
|
using Volo.Abp.Modularity; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
|
|
|
|
namespace Volo.Abp.IdentityServer |
|
|
|
{ |
|
|
|
@ -18,22 +19,15 @@ namespace Volo.Abp.IdentityServer |
|
|
|
{ |
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
{ |
|
|
|
context.Services.AddEntityFrameworkInMemoryDatabase(); |
|
|
|
|
|
|
|
var databaseName = Guid.NewGuid().ToString(); |
|
|
|
var sqliteConnection = CreateDatabaseAndGetConnection(); |
|
|
|
|
|
|
|
Configure<AbpDbContextOptions>(options => |
|
|
|
{ |
|
|
|
options.Configure(abpDbContextConfigurationContext => |
|
|
|
{ |
|
|
|
abpDbContextConfigurationContext.DbContextOptions.UseInMemoryDatabase(databaseName); |
|
|
|
abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Configure<UnitOfWorkDefaultOptions>(options => |
|
|
|
{ |
|
|
|
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
|
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
@ -41,6 +35,22 @@ namespace Volo.Abp.IdentityServer |
|
|
|
SeedTestData(context); |
|
|
|
} |
|
|
|
|
|
|
|
private static SqliteConnection CreateDatabaseAndGetConnection() |
|
|
|
{ |
|
|
|
var connection = new SqliteConnection("Data Source=:memory:"); |
|
|
|
connection.Open(); |
|
|
|
|
|
|
|
new IdentityDbContext( |
|
|
|
new DbContextOptionsBuilder<IdentityDbContext>().UseSqlite(connection).Options |
|
|
|
).GetService<IRelationalDatabaseCreator>().CreateTables(); |
|
|
|
|
|
|
|
new IdentityServerDbContext( |
|
|
|
new DbContextOptionsBuilder<IdentityServerDbContext>().UseSqlite(connection).Options |
|
|
|
).GetService<IRelationalDatabaseCreator>().CreateTables(); |
|
|
|
|
|
|
|
return connection; |
|
|
|
} |
|
|
|
|
|
|
|
private static void SeedTestData(ApplicationInitializationContext context) |
|
|
|
{ |
|
|
|
using (var scope = context.ServiceProvider.CreateScope()) |
|
|
|
|