AppSettings empty in ConfigureServices

At least when debugging, I find that the AppSettings object, while available, does not contain any settings in AppHost’s ConfigureServices method.

TBH in newer SS versions, it’s quite confusing at times which parts require standard .NET and which are SS.

I’ve solved it by instantiating AppSettings from the Configuration object, which is available.

.ConfigureServices((context,services) => {
    // here AppSettings.Get() will return null (AppSettings exists, but is empty)

    AppSettings = new NetCoreAppSettings(context.Configuration);

    // now AppSettings.Get() will return values

ConfigureServices is called before the app is built, so the AppHost wont have even been constructed yet.

Note the AppSettings your initializing isn’t the same AppHost instance that your App is run with, which is created when running:

app.UseServiceStack(new AppHost());

So while they have the same IConfiguration backing store and will result in the same behavior, they wont be the same instance.

In general I’d recommend using ASP .NET Core’s abstraction directly if your App is only going to run on ASP .NET Core as it will be interoperable with the rest of ASP .NET Core classes, e,g, reading from content.Configuration directly.