|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Data.Sqlite;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
|
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
|
|
|
using Volo.Abp.Modularity;
|
|
|
|
|
using Volo.Abp.Uow;
|
|
|
|
@ -15,15 +17,13 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -32,5 +32,17 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore
|
|
|
|
|
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static SqliteConnection CreateDatabaseAndGetConnection()
|
|
|
|
|
{
|
|
|
|
|
var connection = new SqliteConnection("Data Source=:memory:");
|
|
|
|
|
connection.Open();
|
|
|
|
|
|
|
|
|
|
new TenantManagementDbContext(
|
|
|
|
|
new DbContextOptionsBuilder<TenantManagementDbContext>().UseSqlite(connection).Options
|
|
|
|
|
).GetService<IRelationalDatabaseCreator>().CreateTables();
|
|
|
|
|
|
|
|
|
|
return connection;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|