[英]How can I use service configuration in Azure from application level?
I have some cloud service implemented in C#. 我在C#中实现了一些云服务。 Whole solution consists of Service Project with some settings, separate projects for multiple roles + one separate project with main logic of the application. 整个解决方案包括具有某些设置的Service Project,用于多个角色的单独项目+一个具有应用程序主要逻辑的单独项目。 Now, I need to distinguish application url depending on environment it is run on. 现在,我需要根据运行它的环境来区分应用程序URL。 I know (suspect might be better choice of words) I can modify ServiceConfiguration.<Cloud|Local>.cscfg
file by adding <Setting name="domain" value="example.com" />
我知道(怀疑是更好的选择),我可以通过添加<Setting name="domain" value="example.com" />
来修改ServiceConfiguration.<Cloud|Local>.cscfg
文件
Now, the question I'd like to ask is: how can access this configuration value from source code? 现在,我想问的问题是:如何从源代码访问此配置值?
Yes, it is certainly possible. 是的,肯定有可能。 So if you have a cloud project A
and that has a setting <Setting name="domain" value="exampleA.com" />
and then you have cloud project B
that has a setting <Setting name="domain" value="exampleB.com" />
and then you have main project which is used in both cloud projects A and B. 因此,如果您有一个云项目A
且设置为<Setting name="domain" value="exampleA.com" />
,则您有一个云项目B
的设置为<Setting name="domain" value="exampleB.com" />
,然后您拥有在云项目A和B中都使用的主项目。
When you run project A and read the setting domain
from your main project you will get exampleA.com
and when you run project B and read the same setting, you will get exampleB.com
. 当您运行项目A并从主项目中读取设置domain
,您将获得exampleA.com
而当您运行项目B并读取相同的设置时,您将获得exampleB.com
。
I added to the ServiceConfigurationCloud.cscfg and the ServiceConfigurationLocal.cscfg 我添加到ServiceConfigurationCloud.cscfg和ServiceConfigurationLocal.cscfg
<ConfigurationSettings>
<Setting name="DataBaseConnectionString" value="Data Source=MYNAME.database.windows.net;Initial Catalog=MYDATABASE;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD"/>
</ConfigurationSettings>
Then I added to the ServiceDefinition.csdef file. 然后,我将其添加到ServiceDefinition.csdef文件中。
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
<Setting name="DataBaseConnectionString"/>
</ConfigurationSettings>
Within the code I was able to read from the file by using 在代码中,我能够通过使用从文件中读取
string DBCO = RoleEnvironment.GetConfigurationSettingValue("DataBaseConnectionString");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.