Couchbase multiple buckets in .NET app.config

喜欢而已 提交于 2019-11-28 05:50:41

问题


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>

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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/10554175/couchbase-multiple-buckets-in-net-app-config

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