Search code examples
c#azure-service-fabric

Accessing application parameters directly from service


Is it possible to access parameters defined in the ApplicationManifest.xml directly from your SF services?

I know you can define parameters on service level and provide overrides (as described here) but it is very cumbersome. If you have several services accessing same parameter (e.g. connection string) then it would be much easier to have it defined in a single place, like app manifest.


Solution

  • It's possible, but not easy.

    1. Get the manifest xml:
    var fc = new FabricClient();         
    var application = (await fc.QueryManager.GetApplicationListAsync(new Uri (Context.CodePackageActivationContext.ApplicationName))).Single();         
    var applicationManifest = await fc.ApplicationManager.GetApplicationManifestAsync(application.ApplicationTypeName,
     application.ApplicationTypeVersion);
    
    1. Use that xml to deserialize an object based on the XSD schema. C:\Program Files\Microsoft SDKs\Service Fabric\schemas\ServiceFabricServiceModel.xsd (ApplicationManifestType)

    (sorry about the formatting)