選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DataConfigurationExtension.cs 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. namespace Diligent.WebAPI.Host.Extensions;
  2. [ExcludeFromCodeCoverage]
  3. public static class DataConfigurationExtension
  4. {
  5. /// <summary>
  6. /// Services configuration
  7. /// </summary>
  8. public static async void ConfigureData(this WebApplicationBuilder builder)
  9. {
  10. IServiceCollection services = builder.Services;
  11. services.ConfigureData(builder.Configuration);
  12. }
  13. /// <summary>
  14. /// App configuration
  15. /// </summary>
  16. public async static void ConfigureData(this WebApplication app)
  17. {
  18. using (var serviceScope = app.Services.CreateScope())
  19. {
  20. var roleManager = serviceScope.ServiceProvider.GetRequiredService<RoleManager<AppRole>>();
  21. if (!await roleManager.RoleExistsAsync("SuperAdmin"))
  22. {
  23. var managerRole = new AppRole("SuperAdmin");
  24. await roleManager.CreateAsync(managerRole);
  25. }
  26. if (!await roleManager.RoleExistsAsync("Admin"))
  27. {
  28. var managerRole = new AppRole("Admin");
  29. await roleManager.CreateAsync(managerRole);
  30. }
  31. }
  32. DataSeeder.SeedUser(app.Services);
  33. DataSeeder.SeedTags(app.Services);
  34. }
  35. }