Hi, I initiated the Cluster in DI with the following code:
serviceCollection.AddSingleton<ICouchbaseRepository>(service =>
{
var couchbaseOptions = service.GetService<AppSettings>()?.CouchbaseOptions
?? throw new NullReferenceException(nameof(CouchbaseOptions));
var cluster = Cluster.ConnectAsync(new ClusterOptions
{
ConnectionString = couchbaseOptions.ConnectionString,
Buckets = new List<string> { couchbaseOptions.Bucket }, // See here
UserName = couchbaseOptions.Username,
Password = couchbaseOptions.Password
});
return new CouchbaseRepository(cluster);
});
As I specified the bucket name in the initialisation process, how can I access it later without providing the bucket name?
I cannot use something like Cluster.BucketAsync()
as it requires the bucket name here (what’s the point of having to specify the name again when I have specified the desired bucket name previously?).
I tried with Cluster.Buckets.GetAllBucketsAsync()
but I got the ArgumentNullException
; using Cluster.Buckets.GetAllBucketsAsync(new GetAllBucketsOptions())
or Cluster.Buckets.GetAllBucketsAsync(GetAllBucketsOptions.Default)
don’t work either (same errors).
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'value')
at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(Object value, String parameterName)
at Newtonsoft.Json.Linq.Extensions.Value[T,U](IEnumerable`1 value)
at Newtonsoft.Json.Linq.Extensions.Value[U](IEnumerable`1 value)
at Couchbase.Management.Buckets.BucketManager.GetBucketSettings(JToken json)
at Couchbase.Management.Buckets.BucketManager.GetAllBucketsAsync(GetAllBucketsOptions options)
Environment:
- .NET Core 5
- CouchbaseNetClient 3.1.3
- Couchbase Server community-6.6.0
- Runs on Docker