but the line: IBucketProvider .GetBucket("myBucketName", "password")
throws a bootstrap error with an inner exception of nullRefereceException.
When i register a named bucket .AddCouchbaseBucket<IMyBucketName>("myBucketName", "password");
and then inject it i can access any document.
But i don’t want the bucket i use to be decided by the code i need it to be configurable
any way i can define these named buckets in appsettings.json?
Version: 4.1.0-5005 Community Edition (build-5005)
startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddCouchbase(Configuration.GetSection("Couchbase"));
//When i add this i can access my bucket seccussfully
//services.AddCouchbaseBucket<IStatisticsBucket>("statistics");
}
private readonly IBucket _CacheBucket;
// This Works
public ChannelListController(IStatisticsBucket bucketProvider): base()
{
_CacheBucket = bucketProvider.GetBucket();
}
//This does not
public ChannelListController(IBucketProvider bucketProvider): base()
{
_CacheBucket = bucketProvider.GetBucket("statistics", "password");
}
I’m a little confused: you say that the following code works:
// This Works
public ChannelListController(IStatisticsBucket bucketProvider): base()
{
_CacheBucket = bucketProvider.GetBucket();
}
But there is no overload of GetBucket that takes 0 arguments.
So I don’t see how that would be working for you.
To answer your original question, yes, you can certain put a bucket name into the config file and load that from the config file. I don’t think you can do this with Configuration.GetSection alone, you may have to load it separately. I could be wrong, so I’m going to ping @btburnett3 to get his feedback as well.
The INamedBucketProvider implementation does work without a bucket name in GetBucket(). So that part’s fine. But to support that, you must include the section you commented out:
So this will do the trick but feels like a workaroung .
I qould like to use a plain IBucketProvider in my controller and just passe the buclet name… But for some reason i get an error …
I belive that has todo with the Couchbase config section that missing some parameters … But im not sure what …
Just using the plain IBucketProvider should work as well, I’m not sure why you’re getting an exception. The named bucket provider uses IBucketProvider behind the scenes, so I would think that if one was giving an error the other would as well.