Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var securityConnectionString = ConfigurationManager.Instance.GetRequiredSection("ConnectionStrings")["Security"];
- var serverVersion = ServerVersion.AutoDetect(securityConnectionString);
- services.AddDbContextPool<Security.ApplicationLayer.Context.AccessTokenContext>(options =>
- options.UseMySql(securityConnectionString, serverVersion)
- );
- services.AddDbContextPool<Security.ApplicationLayer.Context.UserContext>(options =>
- options.UseMySql(securityConnectionString, serverVersion)
- );
- services.AddDbContextPool<Security.ApplicationLayer.Context.UserGroupContext>(options =>
- options.UseMySql(securityConnectionString, serverVersion)
- );
- services.AddDbContextPool<Security.ApplicationLayer.Context.PermissionContext>(options =>
- options.UseMySql(securityConnectionString, serverVersion)
- );
- services.AddDbContextPool<Security.ApplicationLayer.Context.RoleContext>(options =>
- options.UseMySql(securityConnectionString, serverVersion)
- );
- var serviceProvider = services.BuildServiceProvider();
- var userContext = serviceProvider.GetService<Security.ApplicationLayer.Context.UserContext>();
- var accessTokenContext = serviceProvider.GetService<Security.ApplicationLayer.Context.AccessTokenContext>();
- var userGroupContext = serviceProvider.GetService<Security.ApplicationLayer.Context.UserGroupContext>();
- var permissionContext = serviceProvider.GetService<Security.ApplicationLayer.Context.PermissionContext>();
- var roleContext = serviceProvider.GetService<Security.ApplicationLayer.Context.RoleContext>();
- accessTokenContext.Database.EnsureCreated();
- userContext.Database.EnsureCreated();
- userGroupContext.Database.EnsureCreated();
- permissionContext.Database.EnsureCreated();
- roleContext.Database.EnsureCreated();
- public class UserContext : DbContext
- {
- public DbSet<User> User { get; set; }
- public DbSet<UserCredential> UserCredential { get; set; }
- public UserContext(DbContextOptions<UserContext> options) : base(options)
- {
- Database.EnsureCreated();
- }
- }
- public class AccessTokenContext : DbContext
- {
- public DbSet<AccessToken> AccessToken { get; set; }
- public AccessTokenContext(DbContextOptions<AccessTokenContext> options) : base(options)
- {
- Database.EnsureCreated();
- }
- }
- public class UserGroupContext : DbContext
- {
- public DbSet<UserGroup> UserGroup { get; set; }
- public DbSet<UserInUserGroup> UserInUserGroup { get; set; }
- public DbSet<RoleInUserGroup> RoleInUserGroup { get; set; }
- public UserGroupContext(DbContextOptions<UserGroupContext> options) : base(options)
- {
- Database.EnsureCreated();
- }
- }
- public class PermissionContext : DbContext
- {
- public DbSet<Permission> Permission { get; set; }
- public PermissionContext(DbContextOptions<PermissionContext> options) : base(options)
- {
- Database.EnsureCreated();
- }
- }
- public class RoleContext : DbContext
- {
- public DbSet<Role> Role { get; set; }
- public DbSet<PermissionInRole> PermissionInRole { get; set; }
- public RoleContext(DbContextOptions<RoleContext> options) : base(options)
- {
- Database.EnsureCreated();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement