You should only use the AppHost singleton (i.e. HostContext) after it’s initialized, prior to that (or within your AppHost) you should just access its instance properties instead, e.g:
public override void Configure(Container container)
{
var appSettings = AppSettings;
}
AppSelfHostBase for .NET Core requires the AppHost is started (i.e. both .Init() and .Start()) before the AppHost is properly initialized.
Typically AppSelfHostBase is only used for creating multi-platform (.NET Framework/.NET Core) integration tests as such the default AppSettings looks at the same Web.config/App.config <appSettings/> as .NET Framework integration test projects.
class AppHost : AppSelfHostBase
{
public AppHost() : base(nameof(MyTests), typeof(MyTests).Assembly)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
AppSettings = new NetCoreAppSettings(Configuration);
}
public override void Configure(Container container)
{
var stringValue = AppSettings.GetString(stringKey);
var intValue = AppSettings.Get<int>(intKey);
}
}
Although if you only need to target .NET Core you may want to consider using the standard Program/Startup.cs for ASP .NET Core projects directly (which AppSelfHostBase is just wrapping), to get full configurability of Kestrel SelfHost Server.