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?
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.
来源:https://stackoverflow.com/questions/10554175/couchbase-multiple-buckets-in-net-app-config