From d289e6583194fc50e3415839e485890441b05241 Mon Sep 17 00:00:00 2001 From: Jasmin Oster Date: Wed, 31 Jan 2024 10:45:48 +0100 Subject: [PATCH] SIANXSVC-1186: Exit application after writing metadata --- src/Anexia.E5E/Hosting/E5EHostWrapper.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Anexia.E5E/Hosting/E5EHostWrapper.cs b/src/Anexia.E5E/Hosting/E5EHostWrapper.cs index 8f6d6e6..77d0711 100644 --- a/src/Anexia.E5E/Hosting/E5EHostWrapper.cs +++ b/src/Anexia.E5E/Hosting/E5EHostWrapper.cs @@ -35,21 +35,20 @@ public async Task StartAsync(CancellationToken cancellationToken = default) return; } - string metadata = ""; #if NET8_0_OR_GREATER - metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(), + var metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(), E5ESerializationContext.Default.E5ERuntimeMetadata); #else - metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(), E5EJsonSerializerOptions.Default); + var metadata = JsonSerializer.Serialize(new E5ERuntimeMetadata(), E5EJsonSerializerOptions.Default); #endif _console.Open(); await _console.WriteToStdoutAsync(metadata).ConfigureAwait(false); _console.Close(); - // If we wrote the metadata, circumvent the default host mechanism as used by Run/RunAsync extensions - // and just stop the application. - _host.Services.GetRequiredService().StopApplication(); + // After we wrote the metadata, close the application immediately(!). Any startup tasks that occur after the startup + // (e.g. a long initialization task) won't be executed and the metadata is returned to e5e. + Environment.Exit(0); } public Task StopAsync(CancellationToken cancellationToken = default)