【发布时间】:2015-07-19 21:45:36
【问题描述】:
在 Azure ServiceConfiguration (.cscfg) 中定义配置设置很有吸引力,因为我可以在 Azure 门户中更改该值。
但是,as discussed here Microsoft.WindowsAzure.CloudConfigurationManager.GetSettings("Foo") 将退回到在 app.config 中查找 <appSettings> 值。
是否可以将其退回到Settings.setting 文件?
我可以创建这样的方法,但有更好的/内置方法?
public T GetSetting<T>(string name, T defaultValue = null)
{
return
!RoleEnvironment.IsAvailable
//we could be in a non azure emulated environment (ie unit test)
? defaultValue
: RoleEnvironemt.GetConfigurationSettingValue(name)
??
//in case no value is specified in .cscfg or <appSettings>
defaultValue;
}
然后必须这样称呼它:
var settings = GetSetting("Example", Properties.Settings.Default.Example);
但这很痛苦,我必须指定"Example" 字符串参数
【问题讨论】:
-
它 falls back 已经到 web.config 和 app.config 了。您是否尝试在不签入 cscfg 中的连接字符串的情况下实施 ALM 方案?
-
@OgnyanDimitrov - 基本上,我只是不想在我的应用程序中使用“魔术”字符串来加载配置设置。我想要设置文件中的强类型和编译常量。
-
绝对 - 没有魔法字符串 - 是要走的路。我制作了两个这样的模板 - 一个用于console,一个用于azure 应用程序使用Castle Dictionary Adapter。
标签: c# .net azure configuration settings