RavenDB- Building Session Factory, singleton DocumentStore -
i'm newbie ravendb. i've built ravendb session mill below code. thought much driven way build nhibernatesessionhelpers. hope should work in production. there suggestions improve people experts in ravendb?
public class mxravendbsessionhelper { //---all new lazy singleton that's thread safe.--- private static lazy<idocumentstore> _lazydocstore = new lazy<idocumentstore>(() => initializesessionfactory()); private mxravendbsessionhelper() { } private static idocumentstore sessionfactory { { homecoming _lazydocstore.value; } } public static idocumentsession opensession() { homecoming sessionfactory.opensession(); } private static idocumentstore initializesessionfactory() { var _docstore = new documentstore { connectionstringname = "ravendbconnstring", defaultdatabase = "mxmunky" }; //one more way : _store = new documentstore { url = "http://localhost:7000" }; _docstore.initialize(); _docstore.conventions.identitypartsseparator = "-"; indexcreation.createindexes(typeof(location).assembly, _docstore); homecoming _docstore; } }
i don't think need maintain _docstore
separately. see jon skeet's singleton patterns (#6).
other that, don't see particularly wrong it.
i'd careful not utilize when unit testing. there, do want new docstore instance each test - , should disposed properly.
ravendb
No comments:
Post a Comment