From d7700b14d2ffe5d0dd5f10ede2f7311a8e0e66c5 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 1 Jul 2021 12:00:05 +0300 Subject: [PATCH] Add seeding on start for IdentityService --- .../DbMigrations/IdentityServerDataSeeder.cs | 10 ++++++++-- .../IdentityServiceHttpApiHostModule.cs | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs index bfcc3cd9..160daf32 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using IdentityServer4.Models; using Microsoft.Extensions.Configuration; using Volo.Abp.Authorization.Permissions; +using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.Identity; @@ -21,7 +22,7 @@ using Client = Volo.Abp.IdentityServer.Clients.Client; namespace EShopOnAbp.IdentityService.DbMigrations { - public class IdentityServerDataSeeder : ITransientDependency + public class IdentityServerDataSeeder : IDataSeedContributor, ITransientDependency { private readonly IApiResourceRepository _apiResourceRepository; private readonly IApiScopeRepository _apiScopeRepository; @@ -52,6 +53,11 @@ namespace EShopOnAbp.IdentityService.DbMigrations _currentTenant = currentTenant; } + public virtual Task SeedAsync(DataSeedContext context) + { + return SeedAsync(); + } + [UnitOfWork] public virtual async Task SeedAsync() { @@ -95,7 +101,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations new[] { "IdentityService", "AdministrationService", "SaasService" }); await CreateSwaggerClientAsync("WebGateway", new[] { "IdentityService", "AdministrationService", "SaasService" }); - await CreateSwaggerClientAsync("WebPublicGateway" ); + await CreateSwaggerClientAsync("WebPublicGateway"); } private async Task CreateSwaggerClientAsync(string name, string[] scopes = null) diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs index 517f0b21..7e4d02bb 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs @@ -7,6 +7,7 @@ using EShopOnAbp.Shared.Hosting.Microservices; using Volo.Abp; using Volo.Abp.Modularity; using Volo.Abp.Threading; +using Volo.Abp.Data; namespace EShopOnAbp.IdentityService { @@ -69,6 +70,13 @@ namespace EShopOnAbp.IdentityService .GetRequiredService() .CheckAsync() ); + + AsyncHelper.RunSync(async () => + { + await scope.ServiceProvider + .GetRequiredService() + .SeedAsync(); + }); } } }