.NET app.config 中的 Couchbase 多个存储桶

m03*_*eek 3 .net app-config couchbase

Couchbase .Net 手册说我可以这样配置我的客户端:

<couchbase><servers bucket="default" bucketPassword="">
  <add uri="http://192.168.0.2:8091/pools/default"/>
  <add uri="http://192.168.0.3:8091/pools/default"/>
</servers></couchbase>
Run Code Online (Sandbox Code Playgroud)

有没有办法在 app.config 中定义几个桶,然后在我的应用程序中在它们之间切换?

m03*_*eek 5

根据约翰的建议,我使用了这样的配置:

<configuration>
  <configSections>
    <sectionGroup name="couchbase">
      <section name="bucket-1" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
      ...
      <section name="bucket-N" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
    </sectionGroup>
  </configSections>
  ...
  <couchbase>
    <bucket-1>
      <servers bucket="bucket-1" bucketPassword="pass">
        <add uri="http://10.0.0.1:8091/pools/default"/>
        <add uri="http://10.0.0.2:8091/pools/default"/>
      </servers>
    </bucket-1>
  </couchbase>
  ...
</configuration>
Run Code Online (Sandbox Code Playgroud)

然后在应用程序代码中,您可以获得存储桶的客户端:

var client = new CouchbaseClient((CouchbaseClientSection)ConfigurationManager.GetSection("couchbase/bucket-1"));
Run Code Online (Sandbox Code Playgroud)

如果 .Net couchbase 库的开发人员实现读取这样的配置,那就太好了。