0

私は 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;
    }
}
4

1 に答える 1

2

別に飼う必要はないと思います_docStoreJon Skeet のシングルトン パターン(#6)を参照してください。

それ以外は、特に悪い点は見当たりません。

単体テストではこれを使用しないように注意してください。そこでは、実際にテストごとに新しい docstore インスタンスが必要であり、適切に破棄する必要があります。

于 2013-02-21T21:16:36.157 に答える