I am trying to transition my ServiceStack Self Hosted full framework application to a .Net Core self hosted one.
The full .Net framework one is using TopShelf as follow:
s.ConstructUsing(name => new AppHost());
s.WhenStarted(tc => tc.Start());
s.WhenStopped(tc => tc.Stop());
And a lot of configuration (baseUrl, connection string, originWhiteList) is done in the App.Config file.
Now the selft hosted .Net Core looks like this:
var host = new WebHostBuilder()
which is not using a CreateDefaultBuilder which would pick up the appSettings.json.
Hence what is the best way to get App.Config or appSettings.json accessible to my AppHost?
The selfhost project is an example of creating a .NET Core App with the minimum dependencies, you can use the
AddJsonFile() extension method as shown in Configuration in ASP.NET Core docs to add support for appsettings.json.
Note all .NET Core Apps are self-hosting Core Apps, unless there's a reason to want to use the selfhost template you're likely better off using the web template which uses the default CreateDefaultBuilder() configuration, e.g:
public class Program
public static void Main(string args)
public static IWebHost BuildWebHost(string args) =>
Does this mean that the app we always be running? For instance, I want to use SS along with a daily background job that re-authenticates to the SalesForce Api ( I hate 24 hour bearer tokens) to retrieve a bearer token every 24 hours. This would be on Windows behind IIS.
If running under IIS it looks like IIS will restart it otherwise if running as a Console App it won’t:
That is what I was afraid of. Thanks for the response.
Under IIS you can simply disable automatic pool recycling for the hosting AppPool by setting "Regular Time Interval (minutes)" to 0. Then your app will never recycle, the default value is 1740.
Or just host inside a Windows Service, see https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1