Control lifetime of .NET Core console application hosted in docker Control lifetime of .NET Core console application hosted in docker docker docker

Control lifetime of .NET Core console application hosted in docker


If you're going to host .NET Core apps in Docker I'd recommend just following the normal .NET Core Hosting API where it calls IWebHost.Run() to block the main thread and keep the Console Application alive.

AppHostSelfBase is just a wrapper around .NET Core's hosting API but calls the non-blocking IWebHost.Start() instead. To get the behavior of IWebHost.Run() you should be able to reuse the same approach of ManualResetEventSlim and Console.CancelKeyPress that WebHost.Run()'s implementation uses, but personally it's just easier to use .NET Core's Hosting API and call Run() and just register your ServiceStack AppHost as a .NET Core module.