You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.5 KiB
47 lines
1.5 KiB
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Serilog;
|
|
using Volo.Abp;
|
|
using Win_in.Sfs.Print.Domain;
|
|
|
|
namespace Win_in.Sfs.Print.DbMigrator
|
|
{
|
|
public class DbMigratorHostedService : IHostedService
|
|
{
|
|
private readonly IHostApplicationLifetime _hostApplicationLifetime;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public DbMigratorHostedService(IHostApplicationLifetime hostApplicationLifetime, IConfiguration configuration)
|
|
{
|
|
_hostApplicationLifetime = hostApplicationLifetime;
|
|
_configuration = configuration;
|
|
}
|
|
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
using (var application = AbpApplicationFactory.Create<PrintDbMigratorModule>(options =>
|
|
{
|
|
options.Services.ReplaceConfiguration(_configuration);
|
|
options.UseAutofac();
|
|
options.Services.AddLogging(c => c.AddSerilog());
|
|
}))
|
|
{
|
|
application.Initialize();
|
|
|
|
await application
|
|
.ServiceProvider
|
|
.GetRequiredService<PrintDbMigrationService>()
|
|
.MigrateAsync();
|
|
|
|
application.Shutdown();
|
|
|
|
_hostApplicationLifetime.StopApplication();
|
|
}
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
}
|
|
}
|
|
|