using System; using System.Collections.Generic; using ASC.Common; using ASC.Core.Common.EF.Model; using Microsoft.EntityFrameworkCore; namespace ASC.Core.Common.EF.Context { public class MySqlTenantDbContext : TenantDbContext { } public class PostgreSqlTenantDbContext : TenantDbContext { } public class TenantDbContext : BaseDbContext { public DbSet Tenants { get; set; } public DbSet Users { get; set; } public DbSet UserSecurity { get; set; } public DbSet TenantVersion { get; set; } public DbSet TenantPartner { get; set; } public DbSet TenantForbiden { get; set; } public DbSet TenantIpRestrictions { get; set; } public DbSet CoreSettings { get; set; } public TenantDbContext() { } public TenantDbContext(DbContextOptions options) : base(options) { } protected override Dictionary> ProviderContext { get { return new Dictionary>() { { Provider.MySql, () => new MySqlTenantDbContext() } , { Provider.Postgre, () => new PostgreSqlTenantDbContext() } , }; } } protected override void OnModelCreating(ModelBuilder modelBuilder) { ModelBuilderWrapper .From(modelBuilder, Provider) .AddUser() .AddDbTenant() .AddCoreSettings() .AddUserSecurity() .AddDbTenantForbiden() .AddTenantIpRestrictions() .AddDbTenantPartner() .AddDbTenantVersion(); } } public static class TenantDbExtension { public static DIHelper AddTenantDbContextService(this DIHelper services) { return services.AddDbContextManagerService(); } } }