Skip to content

Commit

Permalink
Use IHostApplicationLifetime to manually terminate the console applic…
Browse files Browse the repository at this point in the history
…ation.

Resolve #3574
  • Loading branch information
maliming committed Apr 13, 2020
1 parent b953f16 commit 4d347cd
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyProjectNameDbMigratorModule>(options =>
Expand All @@ -26,6 +33,8 @@ await application
.MigrateAsync();

application.Shutdown();

_hostApplicationLifetime.StopApplication();
}
}

Expand Down

0 comments on commit 4d347cd

Please sign in to comment.