我是 RavenDb 的新手。我已经像下面的代码一样构建了 RavenDB 会话工厂。这个想法很大程度上来自我们构建 NHibernateSessionHelpers 的方式。我希望这应该在生产中很好地工作。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
{
get
{
return _lazyDocStore.Value;
}
}
public static IDocumentSession OpenSession()
{
return SessionFactory.OpenSession();
}
private static IDocumentStore InitializeSessionFactory()
{
var _docStore = new DocumentStore { ConnectionStringName = "RavenDBConnString", DefaultDatabase = "MXMunky" }; //One more way is this : _store = new DocumentStore { Url = "http://localhost:7000" };
_docStore.Initialize();
_docStore.Conventions.IdentityPartsSeparator = "-";
IndexCreation.CreateIndexes(typeof(Location).Assembly, _docStore);
return _docStore;
}
}