Couchbase multiple buckets in .NET app.config

末鹿安然 提交于 2019-11-29 11:41:56

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>

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

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

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

I found a way around for the above issue.

We can use the CouchbaseClient constructor overload and pass in the bucketname and password. Ex: var client = new CouchbaseClient("default","");

It is not needed to put all bucket config's in the app or web.cong files.

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