我做了這樣的事情,還是不知道,如果它的工作原理:d
public class AzureConfig:StandaloneConfig
{
protected override string GetAppSetting(string name)
{
return RoleEnvironment.GetConfigurationSettingValue(name);
}
protected override string GetConnectionString(string name)
{
return RoleEnvironment.GetConfigurationSettingValue(name);
}
}
public class StandaloneConfig
{
public IndexedSetting AppSettings { get; private set; }
public IndexedSetting ConnectionStrings { get; private set; }
public StandaloneConfig()
{
AppSettings = new IndexedSetting(GetAppSetting);
ConnectionStrings = new IndexedSetting(GetConnectionString);
}
protected virtual String GetAppSetting(String name)
{
return ConfigurationManager.AppSettings[name];
}
protected virtual String GetConnectionString(String name)
{
var cs = ConfigurationManager.ConnectionStrings[name];
if (cs != null)
return cs.ConnectionString;
else
return null;
}
public class IndexedSetting
{
Func<String, String> _getParameter;
public IndexedSetting(Func<String,String> getParameter)
{
_getParameter = getParameter;
}
public String this[String name]
{
get { return _getParameter(name); }
}
}
不要忘記告訴Azure中使用它!
static AzureConfig _config = new AzureConfig();
void Application_Start(object sender, EventArgs e)
{
Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
{
configSetter(_config.AppSettings[configName]);
});
}
如果你使用它讓我知道,我要得到報酬......我的意思是我想知道,如果它的工作原理:d