From a2a4fd203ace8e3ccf3beb155707823137d9640f Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 4 Mar 2020 13:50:09 -0800 Subject: [PATCH] Dispose webapp on StopAsync (#70) --- src/Tye.Hosting/TyeHost.cs | 11 +++++++---- test/E2ETest/TyeRunTest.cs | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Tye.Hosting/TyeHost.cs b/src/Tye.Hosting/TyeHost.cs index 7028b352..e87e935b 100644 --- a/src/Tye.Hosting/TyeHost.cs +++ b/src/Tye.Hosting/TyeHost.cs @@ -19,7 +19,7 @@ namespace Tye.Hosting private Microsoft.Extensions.Logging.ILogger? _logger; private IHostApplicationLifetime? _lifetime; private AggregateApplicationProcessor? _processor; - private WebApplication? _app; + private readonly Application _application; private readonly string[] _args; @@ -29,6 +29,8 @@ namespace Tye.Hosting _args = args; } + public WebApplication? DashboardWebApplication { get; set; } + public async Task RunAsync() { await StartAsync(); @@ -43,7 +45,7 @@ namespace Tye.Hosting public async Task StartAsync() { var app = BuildWebApplication(_application, _args); - _app = app; + DashboardWebApplication = app; ConfigureApplication(app); @@ -83,10 +85,11 @@ namespace Tye.Hosting } finally { - if (_app != null) + if (DashboardWebApplication != null) { // Stop the host after everything else has been shutdown - await _app.StopAsync(); + await DashboardWebApplication.StopAsync(); + DashboardWebApplication.Dispose(); } } } diff --git a/test/E2ETest/TyeRunTest.cs b/test/E2ETest/TyeRunTest.cs index 0ea23bc3..89b8bd03 100644 --- a/test/E2ETest/TyeRunTest.cs +++ b/test/E2ETest/TyeRunTest.cs @@ -17,7 +17,7 @@ namespace E2ETest { var application = ConfigFactory.FromFile(new FileInfo(Path.Combine(GetSolutionRootDirectory("tye"), "samples", "single-project", "test-project", "test-project.csproj"))); var host = new TyeHost(application.ToHostingApplication(), new string[0]); - var webApplication = await host.StartAsync(); + await host.StartAsync(); try { var handler = new HttpClientHandler @@ -30,7 +30,7 @@ namespace E2ETest // Make sure dashboard and applications are up. // Dashboard should be hosted in same process. - var dashboardResponse = await client.GetStringAsync(new Uri(webApplication.Addresses.First())); + var dashboardResponse = await client.GetStringAsync(new Uri(host.DashboardWebApplication!.Addresses.First())); // Only one service for single application. var service = application.Services.First();