2020-11-17 10:00:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using ASC.Common;
|
2020-02-17 08:58:14 +00:00
|
|
|
|
using ASC.Core.Common.EF.Model;
|
2020-10-12 16:23:15 +00:00
|
|
|
|
|
2019-12-03 15:20:21 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2020-10-12 16:23:15 +00:00
|
|
|
|
|
2019-12-03 15:20:21 +00:00
|
|
|
|
namespace ASC.Core.Common.EF.Context
|
|
|
|
|
{
|
2020-10-06 11:38:15 +00:00
|
|
|
|
public class MySqlTenantDbContext : TenantDbContext { }
|
|
|
|
|
public class PostgreSqlTenantDbContext : TenantDbContext { }
|
2020-10-05 09:27:15 +00:00
|
|
|
|
public class TenantDbContext : BaseDbContext
|
2019-12-03 15:20:21 +00:00
|
|
|
|
{
|
|
|
|
|
public DbSet<DbTenant> Tenants { get; set; }
|
|
|
|
|
public DbSet<DbTenantVersion> TenantVersion { get; set; }
|
|
|
|
|
public DbSet<DbTenantPartner> TenantPartner { get; set; }
|
|
|
|
|
public DbSet<DbTenantForbiden> TenantForbiden { get; set; }
|
2019-12-10 14:47:48 +00:00
|
|
|
|
public DbSet<TenantIpRestrictions> TenantIpRestrictions { get; set; }
|
2019-12-03 15:20:21 +00:00
|
|
|
|
public DbSet<DbCoreSettings> CoreSettings { get; set; }
|
|
|
|
|
|
2019-12-17 08:27:38 +00:00
|
|
|
|
public TenantDbContext() { }
|
|
|
|
|
public TenantDbContext(DbContextOptions<TenantDbContext> options)
|
|
|
|
|
: base(options)
|
|
|
|
|
{
|
2020-09-02 15:23:39 +00:00
|
|
|
|
|
2019-12-17 08:27:38 +00:00
|
|
|
|
}
|
2020-10-06 11:38:15 +00:00
|
|
|
|
protected override Dictionary<Provider, Func<BaseDbContext>> ProviderContext
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new Dictionary<Provider, Func<BaseDbContext>>()
|
|
|
|
|
{
|
|
|
|
|
{ Provider.MySql, () => new MySqlTenantDbContext() } ,
|
2021-10-12 10:23:20 +00:00
|
|
|
|
{ Provider.PostgreSql, () => new PostgreSqlTenantDbContext() } ,
|
2020-10-06 11:38:15 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-03 15:20:21 +00:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
2020-10-12 19:39:23 +00:00
|
|
|
|
ModelBuilderWrapper
|
2020-09-02 15:23:39 +00:00
|
|
|
|
.From(modelBuilder, Provider)
|
2020-09-06 22:49:03 +00:00
|
|
|
|
.AddDbTenant()
|
|
|
|
|
.AddCoreSettings()
|
|
|
|
|
.AddDbTenantForbiden()
|
|
|
|
|
.AddTenantIpRestrictions()
|
|
|
|
|
.AddDbTenantPartner()
|
2020-10-05 10:02:28 +00:00
|
|
|
|
.AddDbTenantVersion();
|
2019-12-03 15:20:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class TenantDbExtension
|
|
|
|
|
{
|
2020-02-17 08:58:14 +00:00
|
|
|
|
public static DIHelper AddTenantDbContextService(this DIHelper services)
|
2019-12-03 15:20:21 +00:00
|
|
|
|
{
|
2019-12-10 15:06:51 +00:00
|
|
|
|
return services.AddDbContextManagerService<TenantDbContext>();
|
2019-12-03 15:20:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|