DocSpace-buildtools/common/ASC.Core.Common/EF/Context/TelegramDbContext.cs

49 lines
1.5 KiB
C#
Raw Normal View History

2020-10-06 11:38:15 +00:00
using ASC.Common;
using ASC.Core.Common.EF.Model;
2020-10-12 16:23:15 +00:00
using Microsoft.EntityFrameworkCore;
2020-10-12 16:23:15 +00:00
2020-10-06 11:38:15 +00:00
using System;
using System.Collections.Generic;
namespace ASC.Core.Common.EF.Context
{
2020-10-06 11:38:15 +00:00
public class MySqlTelegramDbContext : TelegramDbContext { }
public class PostgreSqlTelegramDbContext : TelegramDbContext { }
public class TelegramDbContext : BaseDbContext
{
public DbSet<TelegramUser> Users { get; set; }
public TelegramDbContext() { }
public TelegramDbContext(DbContextOptions<TelegramDbContext> options)
: base(options)
{
}
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 MySqlTelegramDbContext() } ,
2020-10-08 09:07:05 +00:00
{ Provider.Postgre, () => new PostgreSqlTelegramDbContext() } ,
2020-10-06 11:38:15 +00:00
};
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
2020-10-10 11:35:05 +00:00
_ = ModelBuilderWrapper
.From(modelBuilder, Provider)
2020-10-05 10:11:15 +00:00
.AddTelegramUsers();
}
}
public static class TelegramDbContextExtension
{
public static DIHelper AddTelegramDbContextService(this DIHelper services)
{
return services.AddDbContextManagerService<TelegramDbContext>();
}
}
}