Browse Source

fix(data-seeder): run the data seeder in a background service

pull/480/head
cKey 4 years ago
parent
commit
33b305fe01
  1. 17
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.Seeder.cs
  2. 3
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs
  3. 21
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/DataSeeder/BackendAdminDataSeederWorker.cs
  4. 21
      aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/DataSeeder/LocalizationManagementDataSeederWorker.cs
  5. 15
      aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/LocalizationManagementHttpApiHostModule.Seeder.cs
  6. 3
      aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/LocalizationManagementHttpApiHostModule.cs
  7. 21
      aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/DataSeeder/PlatformManagementDataSeederWorker.cs
  8. 15
      aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/PlatformManagementHttpApiHostModule.Seeder.cs
  9. 3
      aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/PlatformManagementHttpApiHostModule.cs
  10. 21
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/DataSeeder/RealtimeMessageDataSeederWorker.cs
  11. 13
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.Seeder.cs
  12. 3
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.cs
  13. 21
      aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/DataSeeder/WorkflowManagementDataSeederWorker.cs
  14. 15
      aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.DataSeeder.cs
  15. 3
      aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.cs
  16. 21
      aspnet-core/services/LY.MicroService.identityServer/DataSeeder/IdentityServerDataSeederWorker.cs
  17. 17
      aspnet-core/services/LY.MicroService.identityServer/IdentityServerModule.Seeder.cs
  18. 3
      aspnet-core/services/LY.MicroService.identityServer/IdentityServerModule.cs

17
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.Seeder.cs

@ -1,22 +1,15 @@
using Microsoft.Extensions.DependencyInjection; using LY.MicroService.BackendAdmin.DataSeeder;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Abp.Threading;
namespace LY.MicroService.BackendAdmin; namespace LY.MicroService.BackendAdmin;
public partial class BackendAdminHttpApiHostModule 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 () => services.AddHostedService<BackendAdminDataSeederWorker>();
{
using var scope = context.ServiceProvider.CreateScope();
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync();
});
} }
} }
} }

3
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs

@ -105,6 +105,7 @@ public partial class BackendAdminHttpApiHostModule : AbpModule
ConfigureSwagger(context.Services); ConfigureSwagger(context.Services);
ConfigureMultiTenancy(configuration); ConfigureMultiTenancy(configuration);
ConfigureCors(context.Services, configuration); ConfigureCors(context.Services, configuration);
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment());
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment());
} }
@ -141,7 +142,5 @@ public partial class BackendAdminHttpApiHostModule : AbpModule
app.UseAbpSerilogEnrichers(); app.UseAbpSerilogEnrichers();
// 路由 // 路由
app.UseConfiguredEndpoints(); app.UseConfiguredEndpoints();
SeedData(context);
} }
} }

21
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/DataSeeder/BackendAdminDataSeederWorker.cs

@ -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();
}
}

21
aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/DataSeeder/LocalizationManagementDataSeederWorker.cs

@ -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();
}
}

15
aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/LocalizationManagementHttpApiHostModule.Seeder.cs

@ -1,20 +1,15 @@
using Microsoft.Extensions.DependencyInjection; using LY.MicroService.LocalizationManagement.DataSeeder;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Abp.Threading;
namespace LY.MicroService.LocalizationManagement; namespace LY.MicroService.LocalizationManagement;
public partial class LocalizationManagementHttpApiHostModule 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 () => services.AddHostedService<LocalizationManagementDataSeederWorker>();
await context.ServiceProvider.GetRequiredService<IDataSeeder>()
.SeedAsync());
} }
} }
} }

3
aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/LocalizationManagementHttpApiHostModule.cs

@ -74,6 +74,7 @@ namespace LY.MicroService.LocalizationManagement
ConfigureSwagger(context.Services); ConfigureSwagger(context.Services);
ConfigureMultiTenancy(configuration); ConfigureMultiTenancy(configuration);
ConfigureCors(context.Services, configuration); ConfigureCors(context.Services, configuration);
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment());
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment());
} }
@ -110,8 +111,6 @@ namespace LY.MicroService.LocalizationManagement
app.UseAbpSerilogEnrichers(); app.UseAbpSerilogEnrichers();
// 路由 // 路由
app.UseConfiguredEndpoints(); app.UseConfiguredEndpoints();
SeedData(context);
} }
} }
} }

21
aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/DataSeeder/PlatformManagementDataSeederWorker.cs

@ -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();
}
}

15
aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/PlatformManagementHttpApiHostModule.Seeder.cs

@ -1,20 +1,15 @@
using Microsoft.Extensions.DependencyInjection; using LY.MicroService.PlatformManagement.DataSeeder;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Abp.Threading;
namespace LY.MicroService.PlatformManagement; namespace LY.MicroService.PlatformManagement;
public partial class PlatformManagementHttpApiHostModule 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 () => services.AddHostedService<PlatformManagementDataSeederWorker>();
await context.ServiceProvider.GetRequiredService<IDataSeeder>()
.SeedAsync());
} }
} }
} }

3
aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/PlatformManagementHttpApiHostModule.cs

@ -103,6 +103,7 @@ public partial class PlatformManagementHttpApiHostModule : AbpModule
ConfigureSwagger(context.Services); ConfigureSwagger(context.Services);
ConfigureMultiTenancy(configuration); ConfigureMultiTenancy(configuration);
ConfigureCors(context.Services, configuration); ConfigureCors(context.Services, configuration);
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment());
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment());
} }
@ -141,7 +142,5 @@ public partial class PlatformManagementHttpApiHostModule : AbpModule
app.UseAbpSerilogEnrichers(); app.UseAbpSerilogEnrichers();
// 路由 // 路由
app.UseConfiguredEndpoints(); app.UseConfiguredEndpoints();
SeedData(context);
} }
} }

21
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/DataSeeder/RealtimeMessageDataSeederWorker.cs

@ -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();
}
}

13
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.Seeder.cs

@ -1,20 +1,15 @@
using LINGYUN.Abp.MessageService; using LY.MicroService.RealtimeMessage.DataSeeder;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Volo.Abp;
using Volo.Abp.Threading;
namespace LY.MicroService.RealtimeMessage; namespace LY.MicroService.RealtimeMessage;
public partial class RealtimeMessageHttpApiHostModule 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 () => services.AddHostedService<RealtimeMessageDataSeederWorker>();
await context.ServiceProvider.GetRequiredService<IMessageDataSeeder>()
.SeedAsync());
} }
} }
} }

3
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.cs

@ -100,6 +100,7 @@ namespace LY.MicroService.RealtimeMessage
ConfigureMultiTenancy(configuration); ConfigureMultiTenancy(configuration);
ConfigureHangfireServer(context.Services); ConfigureHangfireServer(context.Services);
ConfigureCors(context.Services, configuration); ConfigureCors(context.Services, configuration);
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment());
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment());
} }
@ -140,8 +141,6 @@ namespace LY.MicroService.RealtimeMessage
app.UseHangfireDashboard(); app.UseHangfireDashboard();
// 路由 // 路由
app.UseConfiguredEndpoints(); app.UseConfiguredEndpoints();
SeedData(context);
} }
} }
} }

21
aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/DataSeeder/WorkflowManagementDataSeederWorker.cs

@ -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();
}
}

15
aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.DataSeeder.cs

@ -1,20 +1,15 @@
using Microsoft.Extensions.DependencyInjection; using LY.MicroService.WorkflowManagement.DataSeeder;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Abp.Threading;
namespace LY.MicroService.WorkflowManagement; namespace LY.MicroService.WorkflowManagement;
public partial class WorkflowManagementHttpApiHostModule 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 () => services.AddHostedService<WorkflowManagementDataSeederWorker>();
await context.ServiceProvider.GetRequiredService<IDataSeeder>()
.SeedAsync());
} }
} }
} }

3
aspnet-core/services/LY.MicroService.WorkflowManagement.HttpApi.Host/WorkflowManagementHttpApiHostModule.cs

@ -92,6 +92,7 @@ public partial class WorkflowManagementHttpApiHostModule : AbpModule
ConfigureSwagger(context.Services); ConfigureSwagger(context.Services);
ConfigureBlobStoring(context.Services, configuration); ConfigureBlobStoring(context.Services, configuration);
ConfigureDistributedLock(context.Services, configuration); ConfigureDistributedLock(context.Services, configuration);
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment());
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment());
// 开发取消权限检查 // 开发取消权限检查
@ -125,7 +126,5 @@ public partial class WorkflowManagementHttpApiHostModule : AbpModule
app.UseAuditing(); app.UseAuditing();
app.UseAbpSerilogEnrichers(); app.UseAbpSerilogEnrichers();
app.UseConfiguredEndpoints(); app.UseConfiguredEndpoints();
SeedData(context);
} }
} }

21
aspnet-core/services/LY.MicroService.identityServer/DataSeeder/IdentityServerDataSeederWorker.cs

@ -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();
}
}

17
aspnet-core/services/LY.MicroService.identityServer/IdentityServerModule.Seeder.cs

@ -1,22 +1,15 @@
using Microsoft.Extensions.DependencyInjection; using LY.MicroService.IdentityServer.DataSeeder;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Abp.Threading;
namespace LY.MicroService.IdentityServer; namespace LY.MicroService.IdentityServer;
public partial class IdentityServerModule 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 () => services.AddHostedService<IdentityServerDataSeederWorker>();
{
using var scope = context.ServiceProvider.CreateScope();
await scope.ServiceProvider.GetRequiredService<IDataSeeder>().SeedAsync();
});
} }
} }
} }

3
aspnet-core/services/LY.MicroService.identityServer/IdentityServerModule.cs

@ -96,6 +96,7 @@ public partial class IdentityServerModule : AbpModule
ConfigureUrls(configuration); ConfigureUrls(configuration);
ConfigureMultiTenancy(configuration); ConfigureMultiTenancy(configuration);
ConfigureCors(context.Services, configuration); ConfigureCors(context.Services, configuration);
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment());
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment()); ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment());
} }
@ -130,7 +131,5 @@ public partial class IdentityServerModule : AbpModule
app.UseAuditing(); app.UseAuditing();
app.UseAbpSerilogEnrichers(); app.UseAbpSerilogEnrichers();
app.UseConfiguredEndpoints(); app.UseConfiguredEndpoints();
SeedData(context);
} }
} }

Loading…
Cancel
Save