Search code examples
configuration-filesazure-service-fabricstateless

Accessing Service Fabric stateless service config values outside the service project


Is there a way to access Service Fabric Stateless Service's custom config values from a different class library project? I can access the configurations currently like this from the StatelessService itself.

var configurationPackage =     Context.CodePackageActivationContext.GetConfigurationPackageObject("Config");
var connectionStringParameter = configurationPackage.Settings.Sections["QueueConfigSection"].Parameters["QueueName"];

How can I access this Context.CodePackageActivationContext from a different project? Or how can I expose the Stateless Service Context to a different project?


Solution

  • Try this:

    var activationContext = FabricRuntime.GetActivationContext();
    var configurationPackage = activationContext.GetConfigurationPackageObject("Config");
    var connectionStringParameter = configurationPackage.Settings.Sections["QueueConfigSection"].Parameters["QueueName"];
    

    Note that this will only work from within the cluster.