using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; namespace StatiKosev.Data; public static class DbSeeder { public const string UserRole = "User"; //applies pending migrations and creates the role every registered visitor gets public static async Task SeedAsync(IServiceProvider services) { using var scope = services.CreateScope(); var sp = scope.ServiceProvider; await sp.GetRequiredService().Database.MigrateAsync(); var roles = sp.GetRequiredService>(); if (!await roles.RoleExistsAsync(UserRole)) await roles.CreateAsync(new IdentityRole(UserRole)); } }