8

How can I access and read parameters definied in PackageRoot/Settings/Settings.xml file from my stateful/stateless service code? For example I have a section DocumentDbConfig with Parameter EndpointUrl:

<Section Name="DocumentDbConfig">
  <Parameter Name="EndpointUrl" Value="{url}"/>
</Section>

And I would like to read it in my code:

public async Task<ServiceActionResult<Result>> GetResult()
{
    _client = new Client({{ EndpointUrl }});  //HOW TO GET ENDPOINT URL FROM SETTINGS?
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Przemek Marcinkiewicz
  • 1,267
  • 1
  • 19
  • 32
  • 1
    Possible duplicate of [Where do you set and access run-time configuration parameters per environment for service fabric?](http://stackoverflow.com/questions/33928204/where-do-you-set-and-access-run-time-configuration-parameters-per-environment-fo) – Sander Sep 21 '16 at 10:45

1 Answers1

0

As long as your code has access to the ServiceContext you can access all of the configuration packages that were deployed with your service. For example:

serviceContext.CodePackageActivationContext.GetConfigurationPackageObject("Config")

where "Config" is the name of the configuration package. From there, you can access all of the sections and keys/values within each section. Be sure to refer to the ConfigurationPackage documentation as a guide on how to access this data, as well as how to listen to events that fire when the configuration package changes.

pixelTitan
  • 455
  • 3
  • 10