Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: .NET (C#) 1.2
Community Wiki and Resources
Wiki: .NET Client Library
Download Client Library
.NET Client Library
Couchbase Developer Guide 2.0
Couchbase Server Manual 2.0
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
1.3 Try it Out!
Chapter Sections
Chapters

1.3.3. Instantiating the Client

Add the following using statements to Program.cs:

using Couchbase;
using Enyim.Caching.Memcached;
using Enyim.Caching.Memcached;
using Newtonsoft.Json;

Couchbase is the namespace containing the client and configuration classes with which you'll work. Enyim.Caching.Memcached contains supporting infrastructure. Recall that Couchbase supports the Memcached protocol and is therefore able to make use of the popular Enyim Memcached client for many of its core key/value operations.

Next create an instance of the client in the Main method. Use the default constructor, which depends on the configuration from app.config.

var client = new CouchbaseClient();

In practice, it's expensive to create clients. The client incurs overhead as it creates connection pools and sets up the thread to get cluster configuration. Therefore, the best practice is to create a single client instance, per bucket, per AppDomain. Creating a static property on a class works well for this purpose. For example:

public static class CouchbaseManager
{
   private readonly static CouchbaseClient _instance;
   
   static CouchbaseManager()
   {
       _instance = new CouchbaseClient();
   }

   public static CouchbaseClient Instance { get { return _instance; } }
}

However, for the purpose of this getting started guide the locally scoped client variable created above is sufficient.