IIS App Recycle on Web.config change

Just want to be sure. I host my ServiceStack API under IIS (never done that before) and I wanted to know what happens when someone edit the web.config. Is the AppHost restarts just as it would if it would be self-hosted and the service being stopped and started again?

Also and the most important, I would like to have most of my settings stored from a small LiteDB NoSQL database rather than in the web.config and have an Admin page to allow me to do the changes.
The thing is that I do a lot of things in the AppHost Configure from those settings. I would have redo all the things happening in there when I detect a change of configuration in my database?

I create my config at the start with db settings and use container.Register(config); so I can injects the settings wherever I need them, but I will need a way to refresh this when db settings are modified. Any clever way to do this?

Thanks for your help.

If someone modifies the Web.config the AppDomain recycles which is basically the same as restarting the ASP .NET process, i.e. it re-runs Global.asax which launches the AppHost again.

ServiceStack’s AppHost.Configure() only runs once at Startup, the only way to re-run App Startup logic is to restart the app.

For your LiteDB you could create an IAppSettings provider, the easiest way is to inherit the AppSettingsBase base class, see DictionarySettings.cs for an example.

Which you can configure your AppHost to use by assigning it to:

AppSettings = new LiteDbSettings(...);

Or use MultiAppSettings if you want multiple configuration sources

Then anywhere you need “live configuration” you would inject the IAppSettings provider instead, e.g:

public class MyService : Services {
    public IAppSettings AppSettings { get; set; }
}

So instead of populating your dependencies with configuration values (which would cache a stale copy of them) you would inject the IAppSettings provider so every configuration access re-queries its underlying LiteDB source.

If you want to continue using a typed config class, you can use computed properties:

public class AppConfig 
{
    IAppSettings settings;
    public (IAppSettings settings) => this.settings = settings;

    public string ASetting => settings.GetString(nameof(ASetting));
    public int IntSetting => settings.Get(nameof(IntSetting), defaultValue:100);
    public ComplexType C => settings.Get<ComplexType>(nameof(ComplexType));
}
1 Like