Override .NET connection string resolution

239 Views Asked by At

Is there a way to override resolution of values from connectionStrings or appSettings sections at run-time? Can't find any appropriate methods in ConfigurationManager class to do that.

The issue I've got is a Nuget package which relies on ConfigurationManager but my application has custom settings storage (I'm talking to you Azure WebJobs SDK where INameResolver doesn't work with ServiceBusAccountAttribute). So the solution (if any) needs to be Azure friendly.

2

There are 2 best solutions below

2
On

Is there a way to override resolution of values from connectionStrings or appSettings sections at run-time?

If you'd like to override the existing settings that you set in App.config or Web.config at runtime, you can try to specify App settings with same key under Application Strings on Azure portal.

For detailed information about Application settings, please refer to this article.

App settings

This section contains name/value pairs that you web app will load on start up.

  • For .NET apps, these settings are injected into your .NET configuration AppSettings at runtime, overriding existing settings.
1
On

For bindings with Azure Functions / WebJobs, INameResolver is the way to do this. ServiceBus should be going through that. I filed https://github.com/Azure/azure-webjobs-sdk/issues/1347 to track fixing this. Please follow that issue for updates.