Accessing Service Fabric stateless service config values outside the service project
Asked Answered
R

1

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?

Reply answered 10/10, 2016 at 14:13 Comment(0)
K
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.

Keishakeisling answered 10/10, 2016 at 14:48 Comment(1)
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.Primulaceous

© 2022 - 2024 — McMap. All rights reserved.