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
Post a Comment