如何访问Azure Service Fabric有状态/无状态服务中的settings.xml? [英] How to access settings.xml in Azure Service Fabric stateful/stateless service?
问题描述
如何从有状态/无状态服务代码访问和读取在 PackageRoot/Settings/Settings.xml 文件中定义的参数? 例如,我有一个带有参数EndpointUrl的DocumentDbConfig部分:
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?
}
推荐答案
只要您的代码有权访问ServiceContext
,您就可以访问与服务一起部署的所有配置包.例如:
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")
其中,"Config"
是配置软件包的名称.从那里,您可以访问所有部分以及每个部分中的键/值.请确保参考 ConfigurationPackage 文档,作为有关如何访问此数据以及如何侦听配置包更改时触发的事件的指南.
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.
这篇关于如何访问Azure Service Fabric有状态/无状态服务中的settings.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!