How to access settings.xml in Azure Service Fabric stateful/stateless service?

送分小仙女□ 提交于 2020-06-14 04:18:28

问题


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?
}

回答1:


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.



来源:https://stackoverflow.com/questions/36640752/how-to-access-settings-xml-in-azure-service-fabric-stateful-stateless-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!