Azure Service Fabric - Application Settings

So far, I got used to store and retrieve the application settings with the following code:


And other variations...

With Azure Service Fabric (ASF) it is a bit more involved, but offers finer granularity over your application settings. The following describes how to store and subsequently retrieve, the application settings in ASF (I added some colors so it will be easier to read. I hope that you are not color blind :-)

Storing values:

In ~\ApplicationPackageRoot\ApplicationManifest.xml

  <Parameter Name="StorageConnectionString" DefaultValue=" Your Default Value" />

The Service Fabric application model enables services to include configuration packages that contain custom key-value pairs that are readable at run time. The values of these settings can also be differentiated by environment by specifying a ConfigOverride in the application manifest (source). For the order in which ASF overrides application setting, see the comment at the end.

<ServiceManifestVersion="1.0.0" />
     <ConfigOverride Name="Config">
          <Section Name="StorageConfig">
          <Parameter Name="StorageConnectionString" Value="[StorageConnectionString]" />
  <ServiceManifestRef ServiceManifestName="YourPkg" ServiceManifestVersion="1.0.0" />

In ~\ApplicationParameters\Cloud.xml

  <Parameter Name="StorageConnectionString" Value="your value" />

You can add the same to your local XMLs (Local.1Node.xml & Local.5Node.xml)

Retrieving values:

Within your actor / service, you can retrieve a value this way:

var storageConfig = ActorService.Context.CodePackageActivationContext.GetConfigurationPackageObject("Config");
var storageConnectionString = storageConfig.Settings.Sections["StorageConfig"].Parameters["StorageConnectionString"].Value;


Service Fabric will always choose from the application parameter file first (if specified), then the application manifest, and finally the configuration package (source)