diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs index 730a7f73693..89b12bcc03a 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs @@ -10,6 +10,13 @@ namespace MyCompanyName.MyProjectName.DbMigrator { public class DbMigratorHostedService : IHostedService { + private readonly IHostApplicationLifetime _hostApplicationLifetime; + + public DbMigratorHostedService(IHostApplicationLifetime hostApplicationLifetime) + { + _hostApplicationLifetime = hostApplicationLifetime; + } + public async Task StartAsync(CancellationToken cancellationToken) { using (var application = AbpApplicationFactory.Create(options => @@ -26,6 +33,8 @@ await application .MigrateAsync(); application.Shutdown(); + + _hostApplicationLifetime.StopApplication(); } }