Browse Source
Merge pull request #480 from colinin/fix-data-seeder
fix(data-seeder): run the data seeder in a background service
pull/489/head
yx lin
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with
161 additions and
75 deletions
-
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.Seeder.cs
-
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs
-
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/DataSeeder/BackendAdminDataSeederWorker.cs
-
aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/DataSeeder/LocalizationManagementDataSeederWorker.cs
-
aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/LocalizationManagementHttpApiHostModule.Seeder.cs
-
aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/LocalizationManagementHttpApiHostModule.cs
-
aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/DataSeeder/PlatformManagementDataSeederWorker.cs
-
aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/PlatformManagementHttpApiHostModule.Seeder.cs
-
aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/PlatformManagementHttpApiHostModule.cs
-
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/DataSeeder/RealtimeMessageDataSeederWorker.cs
-
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.Seeder.cs
-
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.cs
-
aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/DataSeeder/WorkflowManagementDataSeederWorker.cs
-
aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.DataSeeder.cs
-
aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.cs
-
aspnet-core/services/LY.MicroService.identityServer/DataSeeder/IdentityServerDataSeederWorker.cs
-
aspnet-core/services/LY.MicroService.identityServer/IdentityServerModule.Seeder.cs
-
aspnet-core/services/LY.MicroService.identityServer/IdentityServerModule.cs
|
|
|
@ -1,22 +1,15 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
using LY.MicroService.BackendAdmin.DataSeeder; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
|
|
namespace LY.MicroService.BackendAdmin; |
|
|
|
|
|
|
|
public partial class BackendAdminHttpApiHostModule |
|
|
|
{ |
|
|
|
private static void SeedData(ApplicationInitializationContext context) |
|
|
|
private static void ConfigureSeedWorker(IServiceCollection services, bool isDevelopment = false) |
|
|
|
{ |
|
|
|
if (context.GetEnvironment().IsDevelopment()) |
|
|
|
if (isDevelopment) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(async () => |
|
|
|
{ |
|
|
|
using var scope = context.ServiceProvider.CreateScope(); |
|
|
|
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync(); |
|
|
|
}); |
|
|
|
services.AddHostedService<BackendAdminDataSeederWorker>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -105,6 +105,7 @@ public partial class BackendAdminHttpApiHostModule : AbpModule |
|
|
|
ConfigureSwagger(context.Services); |
|
|
|
ConfigureMultiTenancy(configuration); |
|
|
|
ConfigureCors(context.Services, configuration); |
|
|
|
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment()); |
|
|
|
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -141,7 +142,5 @@ public partial class BackendAdminHttpApiHostModule : AbpModule |
|
|
|
app.UseAbpSerilogEnrichers(); |
|
|
|
// 路由
|
|
|
|
app.UseConfiguredEndpoints(); |
|
|
|
|
|
|
|
SeedData(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,21 @@ |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Data; |
|
|
|
|
|
|
|
namespace LY.MicroService.BackendAdmin.DataSeeder; |
|
|
|
|
|
|
|
public class BackendAdminDataSeederWorker : BackgroundService |
|
|
|
{ |
|
|
|
protected IDataSeeder DataSeeder { get; } |
|
|
|
|
|
|
|
public BackendAdminDataSeederWorker(IDataSeeder dataSeeder) |
|
|
|
{ |
|
|
|
DataSeeder = dataSeeder; |
|
|
|
} |
|
|
|
|
|
|
|
protected async override Task ExecuteAsync(CancellationToken stoppingToken) |
|
|
|
{ |
|
|
|
await DataSeeder.SeedAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -0,0 +1,21 @@ |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Data; |
|
|
|
|
|
|
|
namespace LY.MicroService.LocalizationManagement.DataSeeder; |
|
|
|
|
|
|
|
public class LocalizationManagementDataSeederWorker : BackgroundService |
|
|
|
{ |
|
|
|
protected IDataSeeder DataSeeder { get; } |
|
|
|
|
|
|
|
public LocalizationManagementDataSeederWorker(IDataSeeder dataSeeder) |
|
|
|
{ |
|
|
|
DataSeeder = dataSeeder; |
|
|
|
} |
|
|
|
|
|
|
|
protected async override Task ExecuteAsync(CancellationToken stoppingToken) |
|
|
|
{ |
|
|
|
await DataSeeder.SeedAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1,20 +1,15 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
using LY.MicroService.LocalizationManagement.DataSeeder; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
|
|
namespace LY.MicroService.LocalizationManagement; |
|
|
|
|
|
|
|
public partial class LocalizationManagementHttpApiHostModule |
|
|
|
{ |
|
|
|
private void SeedData(ApplicationInitializationContext context) |
|
|
|
private static void ConfigureSeedWorker(IServiceCollection services, bool isDevelopment = false) |
|
|
|
{ |
|
|
|
if (context.GetEnvironment().IsDevelopment()) |
|
|
|
if (isDevelopment) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(async () => |
|
|
|
await context.ServiceProvider.GetRequiredService<IDataSeeder>() |
|
|
|
.SeedAsync()); |
|
|
|
services.AddHostedService<LocalizationManagementDataSeederWorker>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -74,6 +74,7 @@ namespace LY.MicroService.LocalizationManagement |
|
|
|
ConfigureSwagger(context.Services); |
|
|
|
ConfigureMultiTenancy(configuration); |
|
|
|
ConfigureCors(context.Services, configuration); |
|
|
|
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment()); |
|
|
|
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -110,8 +111,6 @@ namespace LY.MicroService.LocalizationManagement |
|
|
|
app.UseAbpSerilogEnrichers(); |
|
|
|
// 路由
|
|
|
|
app.UseConfiguredEndpoints(); |
|
|
|
|
|
|
|
SeedData(context); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,21 @@ |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Data; |
|
|
|
|
|
|
|
namespace LY.MicroService.PlatformManagement.DataSeeder; |
|
|
|
|
|
|
|
public class PlatformManagementDataSeederWorker : BackgroundService |
|
|
|
{ |
|
|
|
protected IDataSeeder DataSeeder { get; } |
|
|
|
|
|
|
|
public PlatformManagementDataSeederWorker(IDataSeeder dataSeeder) |
|
|
|
{ |
|
|
|
DataSeeder = dataSeeder; |
|
|
|
} |
|
|
|
|
|
|
|
protected async override Task ExecuteAsync(CancellationToken stoppingToken) |
|
|
|
{ |
|
|
|
await DataSeeder.SeedAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1,20 +1,15 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
using LY.MicroService.PlatformManagement.DataSeeder; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
|
|
namespace LY.MicroService.PlatformManagement; |
|
|
|
|
|
|
|
public partial class PlatformManagementHttpApiHostModule |
|
|
|
{ |
|
|
|
private void SeedData(ApplicationInitializationContext context) |
|
|
|
private static void ConfigureSeedWorker(IServiceCollection services, bool isDevelopment = false) |
|
|
|
{ |
|
|
|
if (context.GetEnvironment().IsDevelopment()) |
|
|
|
if (isDevelopment) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(async () => |
|
|
|
await context.ServiceProvider.GetRequiredService<IDataSeeder>() |
|
|
|
.SeedAsync()); |
|
|
|
services.AddHostedService<PlatformManagementDataSeederWorker>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -103,6 +103,7 @@ public partial class PlatformManagementHttpApiHostModule : AbpModule |
|
|
|
ConfigureSwagger(context.Services); |
|
|
|
ConfigureMultiTenancy(configuration); |
|
|
|
ConfigureCors(context.Services, configuration); |
|
|
|
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment()); |
|
|
|
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -141,7 +142,5 @@ public partial class PlatformManagementHttpApiHostModule : AbpModule |
|
|
|
app.UseAbpSerilogEnrichers(); |
|
|
|
// 路由
|
|
|
|
app.UseConfiguredEndpoints(); |
|
|
|
|
|
|
|
SeedData(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,21 @@ |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Data; |
|
|
|
|
|
|
|
namespace LY.MicroService.RealtimeMessage.DataSeeder; |
|
|
|
|
|
|
|
public class RealtimeMessageDataSeederWorker : BackgroundService |
|
|
|
{ |
|
|
|
protected IDataSeeder DataSeeder { get; } |
|
|
|
|
|
|
|
public RealtimeMessageDataSeederWorker(IDataSeeder dataSeeder) |
|
|
|
{ |
|
|
|
DataSeeder = dataSeeder; |
|
|
|
} |
|
|
|
|
|
|
|
protected async override Task ExecuteAsync(CancellationToken stoppingToken) |
|
|
|
{ |
|
|
|
await DataSeeder.SeedAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1,20 +1,15 @@ |
|
|
|
using LINGYUN.Abp.MessageService; |
|
|
|
using LY.MicroService.RealtimeMessage.DataSeeder; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
|
|
|
|
namespace LY.MicroService.RealtimeMessage; |
|
|
|
|
|
|
|
public partial class RealtimeMessageHttpApiHostModule |
|
|
|
{ |
|
|
|
private void SeedData(ApplicationInitializationContext context) |
|
|
|
private static void ConfigureSeedWorker(IServiceCollection services, bool isDevelopment = false) |
|
|
|
{ |
|
|
|
if (context.GetEnvironment().IsDevelopment()) |
|
|
|
if (isDevelopment) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(async () => |
|
|
|
await context.ServiceProvider.GetRequiredService<IMessageDataSeeder>() |
|
|
|
.SeedAsync()); |
|
|
|
services.AddHostedService<RealtimeMessageDataSeederWorker>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -100,6 +100,7 @@ namespace LY.MicroService.RealtimeMessage |
|
|
|
ConfigureMultiTenancy(configuration); |
|
|
|
ConfigureHangfireServer(context.Services); |
|
|
|
ConfigureCors(context.Services, configuration); |
|
|
|
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment()); |
|
|
|
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -140,8 +141,6 @@ namespace LY.MicroService.RealtimeMessage |
|
|
|
app.UseHangfireDashboard(); |
|
|
|
// 路由
|
|
|
|
app.UseConfiguredEndpoints(); |
|
|
|
|
|
|
|
SeedData(context); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,21 @@ |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Data; |
|
|
|
|
|
|
|
namespace LY.MicroService.WorkflowManagement.DataSeeder; |
|
|
|
|
|
|
|
public class WorkflowManagementDataSeederWorker : BackgroundService |
|
|
|
{ |
|
|
|
protected IDataSeeder DataSeeder { get; } |
|
|
|
|
|
|
|
public WorkflowManagementDataSeederWorker(IDataSeeder dataSeeder) |
|
|
|
{ |
|
|
|
DataSeeder = dataSeeder; |
|
|
|
} |
|
|
|
|
|
|
|
protected async override Task ExecuteAsync(CancellationToken stoppingToken) |
|
|
|
{ |
|
|
|
await DataSeeder.SeedAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1,20 +1,15 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
using LY.MicroService.WorkflowManagement.DataSeeder; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
|
|
namespace LY.MicroService.WorkflowManagement; |
|
|
|
|
|
|
|
public partial class WorkflowManagementHttpApiHostModule |
|
|
|
{ |
|
|
|
private void SeedData(ApplicationInitializationContext context) |
|
|
|
private static void ConfigureSeedWorker(IServiceCollection services, bool isDevelopment = false) |
|
|
|
{ |
|
|
|
if (context.GetEnvironment().IsDevelopment()) |
|
|
|
if (isDevelopment) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(async () => |
|
|
|
await context.ServiceProvider.GetRequiredService<IDataSeeder>() |
|
|
|
.SeedAsync()); |
|
|
|
services.AddHostedService<WorkflowManagementDataSeederWorker>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -92,6 +92,7 @@ public partial class WorkflowManagementHttpApiHostModule : AbpModule |
|
|
|
ConfigureSwagger(context.Services); |
|
|
|
ConfigureBlobStoring(context.Services, configuration); |
|
|
|
ConfigureDistributedLock(context.Services, configuration); |
|
|
|
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment()); |
|
|
|
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
|
|
|
|
|
|
|
// 开发取消权限检查
|
|
|
|
@ -125,7 +126,5 @@ public partial class WorkflowManagementHttpApiHostModule : AbpModule |
|
|
|
app.UseAuditing(); |
|
|
|
app.UseAbpSerilogEnrichers(); |
|
|
|
app.UseConfiguredEndpoints(); |
|
|
|
|
|
|
|
SeedData(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,21 @@ |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Data; |
|
|
|
|
|
|
|
namespace LY.MicroService.IdentityServer.DataSeeder; |
|
|
|
|
|
|
|
public class IdentityServerDataSeederWorker : BackgroundService |
|
|
|
{ |
|
|
|
protected IDataSeeder DataSeeder { get; } |
|
|
|
|
|
|
|
public IdentityServerDataSeederWorker(IDataSeeder dataSeeder) |
|
|
|
{ |
|
|
|
DataSeeder = dataSeeder; |
|
|
|
} |
|
|
|
|
|
|
|
protected async override Task ExecuteAsync(CancellationToken stoppingToken) |
|
|
|
{ |
|
|
|
await DataSeeder.SeedAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1,22 +1,15 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
using LY.MicroService.IdentityServer.DataSeeder; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
|
|
namespace LY.MicroService.IdentityServer; |
|
|
|
|
|
|
|
public partial class IdentityServerModule |
|
|
|
{ |
|
|
|
private void SeedData(ApplicationInitializationContext context) |
|
|
|
private static void ConfigureSeedWorker(IServiceCollection services, bool isDevelopment = false) |
|
|
|
{ |
|
|
|
if (context.GetEnvironment().IsDevelopment()) |
|
|
|
if (isDevelopment) |
|
|
|
{ |
|
|
|
AsyncHelper.RunSync(async () => |
|
|
|
{ |
|
|
|
using var scope = context.ServiceProvider.CreateScope(); |
|
|
|
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync(); |
|
|
|
}); |
|
|
|
services.AddHostedService<IdentityServerDataSeederWorker>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -96,6 +96,7 @@ public partial class IdentityServerModule : AbpModule |
|
|
|
ConfigureUrls(configuration); |
|
|
|
ConfigureMultiTenancy(configuration); |
|
|
|
ConfigureCors(context.Services, configuration); |
|
|
|
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment()); |
|
|
|
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -130,7 +131,5 @@ public partial class IdentityServerModule : AbpModule |
|
|
|
app.UseAuditing(); |
|
|
|
app.UseAbpSerilogEnrichers(); |
|
|
|
app.UseConfiguredEndpoints(); |
|
|
|
|
|
|
|
SeedData(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|