Browse Source

Add seeding on start for IdentityService

pull/1/head
enisn 5 years ago
parent
commit
d7700b14d2
  1. 10
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs
  2. 8
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs

10
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using IdentityServer4.Models; using IdentityServer4.Models;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Authorization.Permissions; using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.Identity; using Volo.Abp.Identity;
@ -21,7 +22,7 @@ using Client = Volo.Abp.IdentityServer.Clients.Client;
namespace EShopOnAbp.IdentityService.DbMigrations namespace EShopOnAbp.IdentityService.DbMigrations
{ {
public class IdentityServerDataSeeder : ITransientDependency public class IdentityServerDataSeeder : IDataSeedContributor, ITransientDependency
{ {
private readonly IApiResourceRepository _apiResourceRepository; private readonly IApiResourceRepository _apiResourceRepository;
private readonly IApiScopeRepository _apiScopeRepository; private readonly IApiScopeRepository _apiScopeRepository;
@ -52,6 +53,11 @@ namespace EShopOnAbp.IdentityService.DbMigrations
_currentTenant = currentTenant; _currentTenant = currentTenant;
} }
public virtual Task SeedAsync(DataSeedContext context)
{
return SeedAsync();
}
[UnitOfWork] [UnitOfWork]
public virtual async Task SeedAsync() public virtual async Task SeedAsync()
{ {
@ -95,7 +101,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations
new[] { "IdentityService", "AdministrationService", "SaasService" }); new[] { "IdentityService", "AdministrationService", "SaasService" });
await CreateSwaggerClientAsync("WebGateway", await CreateSwaggerClientAsync("WebGateway",
new[] { "IdentityService", "AdministrationService", "SaasService" }); new[] { "IdentityService", "AdministrationService", "SaasService" });
await CreateSwaggerClientAsync("WebPublicGateway" ); await CreateSwaggerClientAsync("WebPublicGateway");
} }
private async Task CreateSwaggerClientAsync(string name, string[] scopes = null) private async Task CreateSwaggerClientAsync(string name, string[] scopes = null)

8
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs

@ -7,6 +7,7 @@ using EShopOnAbp.Shared.Hosting.Microservices;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Threading; using Volo.Abp.Threading;
using Volo.Abp.Data;
namespace EShopOnAbp.IdentityService namespace EShopOnAbp.IdentityService
{ {
@ -69,6 +70,13 @@ namespace EShopOnAbp.IdentityService
.GetRequiredService<IdentityServiceDatabaseMigrationChecker>() .GetRequiredService<IdentityServiceDatabaseMigrationChecker>()
.CheckAsync() .CheckAsync()
); );
AsyncHelper.RunSync(async () =>
{
await scope.ServiceProvider
.GetRequiredService<IDataSeeder>()
.SeedAsync();
});
} }
} }
} }

Loading…
Cancel
Save