Updating AppSettings created with NetCoreAppSettings to add additional settings from a settings.txt file(s)

I have a .Net Core WebHost Startup class, and within that a Configure method that calls

            app.UseServiceStack(new SSAppHost() {
                AppSettings=new NetCoreAppSettings(Configuration)
            });

thus, SSAppHost‘s AppSettings is already populated with the contents of the WebHost’s ConfigurationRoot when the SSAppHost class’ Configure method is called.

Within SSAppHost.Configure I’m loading a list of PlugIns.

Right now, I am putting all my settings, for the SSAppHost and for every PlugIn, into the host’s configuration files, but I’d like make it more granular, and have separate settings file for the SSAppHost and for each PlugIn.

I do not see any way within SSAppHost.Configure to read a settings.txt file into the instance of AppSettings that is set by the constructor. Is that possible? perhaps I’m just overlooking the correct way?..

And further down the line, in each PlugIn's Configure method, I’d like to read a settings.txt file specific for each PlugIn into the SSAppHost.AppSettings. Would this be possible?

You can use MultiAppSettings to specify a number of different cascading AppSettings providers, the TextFilesSettings provider lets you have simple key/value text file settings, otherwise if you want to store settings using your own configuration format you can read it yourself and populate them in a DictionarySettings provider.

Although you don’t need to have all AppSettings providers in your App’s IAppSettings configuration source, e.g. you can just inject a custom AppSettings provider for each plugin, but it then wont be globally available from HostContext.AppSettings.

Thank you, yes, I have been using MultiAppSettingsBuilder, with AddDictionary and AddTextFile providers, but MultiAppSettingsBuilder.Build returns an IAppSettings object, and new NetCoreAppSettings(configuration) also returns an IAppSettings object. I see no way to combine the two AppSettings objects into a single AppSettings.

I’d like to end up with one globally available HostContext.AppSettings with cascading AppSettings providers that start with the information from the .NetCore ConfigurationRoot, and then adds information from settings file for SSAppHost, then adds information from settings files for each PlugIn. Is there way to accomplish that?

Otherwise I’ll just go with having the HostContext.AppSettings be the SS App-specific configuration information read from dictionary and settings files, and inject a 2nd AppSettings that will hold theNetCoreAppSettings, and inject additional AppSettings for each PlugIn.

That’s what MultiAppSettings lets you do, e.g:

AppSettings = new MultiAppSettings(
    new EnvironmentVariableSettings(),
    new TextFileSettings("~/appsettings.txt".MapHostAbsolutePath(),
    new NetCoreAppSettings(Configuration));

Ah! I’ve been using the MultiAppSettingsBuilder, not new’ing up an MultiAppSettings. I don’t think that the MultiAppSettingsBuilder has an .AddNetCoreAppSettings(Configuration) extension method yet, does it? I’ll have to do a re-write to use new MultiAppSettings(...) instead of the Builder pattern. Thanks for your explanations!

I visited the source code for MultiAppSettingsBuilder this morning,intending to replicate a simplified version and implement my own AddNetCore, and I see that you added this to the source code last night. Awesome! But… I’m targeting .Net Core, and the recent addition is only present in NetStandard2_0. I made a local copy of the class, took out the #if NETSTANDARD2_0, and it works (but only smoketested it, I’ll test in depth later today) .

I’m using my local copy of MultiAppSettingsBuilder and able to continue progress, but would it be possible to include the new AddNetCore method to MultiAppSettingsBuilder targeting .Net Core, so I can eliminate my local copy and use the official SS version?

thanks again for quick reply, good info and awesome turnaround time to implement!

The .NET Standard builds are for .NET Core so if you use the latest v5.5.1 from MyGet you’ll have the AddNetCore() API available.

Thank you! Working as expected.

1 Like