dependency injection - Managing DI for Couchbase client -


with ravendb piece of cake:

public class dataaccessmodule : ninjectmodule {     public override void load() {         bind<idocumentstore>().tomethod(             context => {                 var documentstore = new embeddabledocumentstore {                     datadirectory = @"~/app_data/database",                     useembeddedhttpserver = true                 };                 return documentstore.initialize();             }        ).insingletonscope();          bind<idocumentsession>().tomethod(context =>             context.kernel.get<idocumentstore>().opensession()         ).inrequestscope();     } } 

how 1 manage dependency injection couchbase .net client?

according this page, under heading "instantiating client":

in practice, it's expensive create clients. client incurs overhead creates connection pools , sets thread cluster configuration. therefore, best practice create single client instance, per bucket, per appdomain.

unlike ravendb, not appear couchdb has "session" or other unit-of-work container has instantiated per request.

therefore, if want use di container ninject, register couchbaseclient class singleton, using icouchbaseclient interface.

bind<icouchbaseclient>().tomethod(         context => {             var client = new couchbaseclient();             // else need init client here             return client;         }    ).insingletonscope(); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -