2015-12-07 177 views
1

我們最近將我們的ServiceStack應用程序轉換爲Azure雲服務。ServiceStack + Azure雲服務(CloudConfigurationManager)

我們發現,在內部,ServiceStack並不知道它需要使用CloudServiceConfiguration管理器而不是ConfigurationManager加載配置設置(如oauth.RedirectUrl)。

有沒有辦法連接適用於新環境的ServiceStack?

謝謝!

回答

2

有沒有AppSettings provider爲天青CloudServiceConfiguration,它應該很容易通過繼承AppSettingsBase和壓倒一切的GetNullableString()否則,最簡單的方法就是來填充Dictionary<string,string>從Azure的配置並加載它們爲DictionarySettings,比如建立一個:

AppSettings = new DictionarySettings(azureSettings); 

如果你想兩者的Web.config <appSettings/>和Azure的設置在一起,你應該使用MultiAppSettings使用您的APPHOST構造的AppSettings的級聯來源,例如:

AppSettings = new MultiAppSettings(
    new DictionarySettings(azureSettings), 
    new AppSettings()); 
+0

查看下方較近的答案,謝謝。 – Darren

0

您不需要使用'MultiAppSettings',因爲CloudConfigurationManager將回退到您的配置設置部分。 (appsettings only

從我的測試看來你似乎並不需要任何東西在asp.net 網站的web.config設置似乎得到某種方式與蔚藍的設置覆蓋。在webjob但是,您將需要使用CloudConfigurationManager ...下面是一個適當的實施服務棧AppSettings提供程序來包裝它。

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); 
    } 
}