So there is a couple of things you need to do in order to correctly setup configuration in Azure.
Any configuration that you plan to use must be defined in the Service Definition and configured in the Service Configuration.
Service Definition
The following service definition defines that I will I have a configuration setting named "myWebRoleSetting", notice that I don't define the value at this point, just the fact that I will be configuring this value for the service. This is defined in my Service Definition (ServiceDefinition.csdef)
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="HelloWorldWeb" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="WebRole">
<InputEndpoints>
<!-- Must use port 80 for http and port 443 for https when running in the cloud -->
<InputEndpoint name="HttpIn" protocol="http" port="80" />
</InputEndpoints>
<ConfigurationSettings>
<Setting name="myWebRoleSetting"/>
</ConfigurationSettings>
</WebRole>
</ServiceDefinition>
Service Configuration
Once I have defined my configuration setting, I need to specify the value to use at runtime. This is configured in my Serive Configuration file (ServiceConfiguration.cscfg)
<?xml version="1.0"?>
<ServiceConfiguration serviceName="HelloWorldWeb" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
<Role name="WebRole">
<Instances count="1"/>
<ConfigurationSettings>
<Setting name="myWebRoleSetting" value="Hello World 2"/>
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
Accessing the configuration setting from my application
So once i have defined and configured my configuration setting. I will obviously want to access within my application. This is accessed via the RoleManager.
The following sample shows how you access the previously defined configuration setting.
RoleManager.GetConfigurationSetting("myWebRoleSetting")
As said in previous posts, that if you want your application to run both in and out of the Fabric, then you will need to abstract configuration into a common class.
No comments:
Post a Comment