// Startup.cs public class Startup { public void ConfigureServices(IServiceCollection services) { // ... snip ... services .AddCouchbase(Configuration.GetSection("Couchbase")) .AddCouchbaseBucket(Configuration.GetValue("Couchbase:BucketName")); // ... snip ... } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime applicationLifetime) { // ... snip .. applicationLifetime.ApplicationStopped.Register(() => { Trace.WriteLine("***** T SHUTTING DOWN COUCHBASE *****"); Debug.WriteLine("***** D SHUTTING DOWN COUCHBASE *****"); app.ApplicationServices.GetRequiredService().Close(); }); } } // appsettings.config { "Logging": { "LogLevel": { "Default": "Warning" } }, "AllowedHosts": "*", "Couchbase": { "ConnectionString" : "couchbase://couchbaseLocation", "Username": "", "Password": "", "BucketName": "twitchchat" }, // ... snip ... } // typical use of bucket provider: using System; using System.Threading; using System.Threading.Tasks; using MattsTwitchBot.Core.Models; using MediatR; using Microsoft.Extensions.Options; using TwitchLib.Client.Interfaces; namespace MattsTwitchBot.Core.Notifications { public class BroadcastNotifications : INotificationHandler { private readonly ITwitchBucketProvider _bucketProvider; // ... snip ... public BroadcastNotifications(ITwitchClient twitchClient, IOptions twitchOptions, ITwitchBucketProvider bucketProvider) { _bucketProvider = bucketProvider; // ... snip ... } public async Task Handle(MinuteHeartbeatNotification notification, CancellationToken cancellationToken) { var bucket = await _bucketProvider.GetBucketAsync(); var coll = bucket.DefaultCollection(); var chatNotificationInfoDoc = await coll.GetAsync("chatNotificationInfo"); // ... snip ... } } }