emargee edited this page Feb 19, 2011 · 5 revisions
Clone this wiki locally

A basic connection object through which all traffic is passed to the CouchDB server.

Usage – Creation

Create a basic connection (will connect to port 80 by default)..

var ch = new CouchConnection("http://localhost");

.. but you can specify a port if needed ..

var ch = new CouchConnection("http://localhost",5984);

.. or include in the Url ..

var ch = new CouchConnection("http://localhost:5984");

Usage – Cache

CouchNet comes with a simple caching object that can be instantiated and added to the connection object

var conn = new CouchConnection("http://localhost:5984");
var cache = new HttpRuntimeCache();
cache.ExpirationWindow = 5; //default is 10 minutes
conn.Cache = cache;

.. this example will hold GET requests in memory for 5 minutes (default is 10 minutes).
It is easy to implement your own cache implementation, using the ICouchCache interface, if needed.

Caching can be disabled (or re-enabled) at any time using :


.. or ..


Overriding / Unit Testing

If you want to use a different Http Transport (Client) than the built-in one you can implement your own IHttpTransportFactory / IHttpTransport.
This is also useful for unit testing.

var factory = new Mock<IHttpTransportFactory>(MockBehavior.Strict);
var transport = new Mock<IHttpTransport>(MockBehavior.Strict);
factory.Setup(x => x.Create(new UriBuilder("http://localhost:5984/").Uri)).Returns(transport.Object);

var conn = new CouchConnection("http://localhost:5984", factory.Object);