using LANCommander.Server.Data; using LANCommander.Server.Data.Models; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LANCommander.Server.Services.Factories { public class CustomUserStore : UserStore { public CustomUserStore(DatabaseContext context) : base(context) { } } public class CustomRoleStore : RoleStore { public CustomRoleStore(DatabaseContext context) : base(context) { } } public class IdentityContext : IDisposable { public readonly DatabaseContext DatabaseContext; public readonly UserManager UserManager; public readonly RoleManager RoleManager; public IdentityContext(DatabaseContext databaseContext, IServiceProvider serviceProvider) { DatabaseContext = databaseContext; var userStore = new CustomUserStore(DatabaseContext); UserManager = new UserManager( userStore, serviceProvider.GetRequiredService>(), serviceProvider.GetRequiredService>(), serviceProvider.GetRequiredService>>(), serviceProvider.GetRequiredService>>(), serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService>>()); var roleStore = new CustomRoleStore(DatabaseContext); RoleManager = new RoleManager( roleStore, serviceProvider.GetRequiredService>>(), serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService>>()); } public void Dispose() { DatabaseContext.Dispose(); } } public class IdentityContextFactory { private readonly DatabaseContext DatabaseContext; private readonly IServiceProvider ServiceProvider; public IdentityContextFactory(DatabaseContext databaseContext, IServiceProvider serviceProvider) { DatabaseContext = databaseContext; ServiceProvider = serviceProvider; } public IdentityContext Create() { return new IdentityContext(DatabaseContext, ServiceProvider); } } }