7

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?

Prasadi
  • 97
  • 7

1 Answers1

12

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.

LoekD
  • 11,402
  • 17
  • 27
  • Key part here for me was "will only work from within the cluster". I had to run the service on my local cluster, then trigger an endpoint that would try to get the context from the library. A unit test that calls the library would fail as it's not running on a cluster. – OpMt Jan 06 '23 at 11:03