在.NET中的app.config Couchbase多个桶 [英] Couchbase multiple buckets in .NET app.config

查看:170
本文介绍了在.NET中的app.config Couchbase多个桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Couchbase净手册上说,我可以配置我的客户以这种方式:

Couchbase .Net manual says that I can configure my client in this way:

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

有什么方法来定义的app.config sevral水桶,在我的应用程序,它们之间切换?

Is there any way to define sevral buckets in app.config and then switch between them in my app?

推荐答案

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

According to John's suggestion, I used such configuration:

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

然后在app code就可以得到水桶的客户:

Then in app code you can get bucket's client:

var client = new CouchbaseClient((CouchbaseClientSection)ConfigurationManager.GetSection("couchbase/bucket-1"));

这将是很好,如果净couchbase库的开发人员实现读这样的配置。

It would be nice, if developers of .Net couchbase library implement reading such configuration.

这篇关于在.NET中的app.config Couchbase多个桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆