using Microsoft.AspNetCore.Identity; namespace MyDarling.Models; public class IdentitySeedData { public static void CreateAdminAccount(IServiceProvider serviceProvider, IConfiguration configuration) { CreateAdminAccountAsync(serviceProvider, configuration).Wait(); } public static async Task CreateAdminAccountAsync(IServiceProvider serviceProvider, IConfiguration configuration) { serviceProvider = serviceProvider.CreateScope().ServiceProvider; UserManager userManager = serviceProvider.GetRequiredService>(); string username = configuration["ADMIN_USERNAME"] ?? "admin"; string password = configuration["ADMIN_PASSWORD"] ?? "Password123$"; if (await userManager.FindByNameAsync(username) == null) { IdentityUser adminUser = new IdentityUser { UserName = username }; IdentityResult result = await userManager.CreateAsync(adminUser, password); } } }