在 Azure Service Fabric 应用程序中存储非键值参数的位置



我想向我的应用程序添加自定义设置,如下所示:

<Parameter Name="AuthService1" url="http://localhost:11200/" method="post" value3="123" />
<Parameter Name="AuthService2" url="https://auth.com/" method="get" value3="133" />

或者分组键值参数,如下所示:

<subSettings name="AuthService1">
<parametr name="url" value ="http://localhost:11200/" />
<parametr name="method" value ="post" />
<subSettings/>
<subSettings name="AuthService2">
<parametr name="url" value ="https://auth.com/" />
<parametr name="method" value ="get" />
<subSettings/>

我可以在哪里存储它?

我能想到的一些选择:

  1. 使用 json(或 xml(作为值,如下所示:

    <Parameter Name="AuthService1" Value="{&quot;Url&quot;:&quot;http://localhost:11200/&quot;,&quot;Method&quot;:&quot;post&quot;,&quot;value3&quot;:123}">
    
  2. 使用多个参数,如下所示:

    <Parameter Name="AuthService1.Url" Value="http://localhost:11200/" /> 
    <Parameter Name="AuthService1.Method" Value="Post" /> 
    <Parameter Name="AuthService1.Value3" Value="123" /> 
    

如果要解决这个问题,我宁愿采用分组方法。可以在 Service Fabric"设置.xml"中包含如下部分:

<Section Name="AuthService1">
<Parameter Name="Url" Value="http://localhost:11200/" />
<Parameter Name="Method" Value="POST" />
</Section>

现在,如果要在代码中访问这些设置,则需要执行以下操作:

Configuration.GetSection("AuthService1")["Url"];

Configuration["AuthService1:Url"];

在上面给出的示例中,我假设配置是Microsoft.Extensions.IConfiguration对象。

最新更新