1

We've recently converted our ServiceStack application to an Azure Cloud Service.

We're finding that, internally, ServiceStack is not aware that it needs to load configuration settings (like oauth.RedirectUrl) using CloudServiceConfiguration manager instead of ConfigurationManager.

Is there a way to wire up ServiceStack appropriate for the new environment?

Thanks!

josh-sachs
  • 1,749
  • 2
  • 15
  • 19

2 Answers2

2

There's no AppSettings provider for Azure CloudServiceConfiguration, it should be fairly easy to create one by inheriting AppSettingsBase and overriding GetNullableString() otherwise the easiest way is to populate a Dictionary<string,string> with the configuration from Azure and load them into DictionarySettings, e.g:

AppSettings = new DictionarySettings(azureSettings);

If you want to both Web.config <appSettings/> and Azure Settings together you should use a cascading source of AppSettings in your AppHost constructor using MultiAppSettings, e.g:

AppSettings = new MultiAppSettings(
    new DictionarySettings(azureSettings),
    new AppSettings());
mythz
  • 141,670
  • 29
  • 246
  • 390
0

You don't need to use 'MultiAppSettings' because CloudConfigurationManager will fall back to your config appsettings section. (appsettings only)

From my testing it seems you don't seem to need anything at all in asp.net website as web.config settings seem to get somehow overridden with azure settings. In a webjob however you will need to use the CloudConfigurationManager ...below is a suitable implementation of an servicestack AppSettings provider to wrap it.

public class AzureCloudSettings : AppSettingsBase
{
    private class CloudConfigurationManagerWrapper : ISettings
    {
        public string Get(string key)
        {
            return CloudConfigurationManager.GetSetting(key, false);
        }

        public List<string> GetAllKeys()
        {
            throw new NotImplementedException("Not possible with CloudConfigurationManager");
        }
    }

    public AzureCloudSettings() : base(new CloudConfigurationManagerWrapper()) { }

    public override string GetString(string name)
    {
        return GetNullableString(name);
    }

    public override string GetNullableString(string name)
    {
        return base.Get(name);
    }
}
Community
  • 1
  • 1
Darren
  • 9,014
  • 2
  • 39
  • 50