1

Ninject のInRequestScope拡張機能に問題があります。IDocumentSession同じリクエスト内で の新しいインスタンスを取得しているようです。ASP.NET MVC 4 ベータ版を使用して、組み込みの HttpServer として RavenDb を実行しています。次のようなブートストラップ クラスがあります。

public static class ApplicationBootstrapper
{
    private static IKernel _kernel;

private static readonly IDocumentStore DocumentStore = new EmbeddableDocumentStore
{
    DataDirectory  = @"App_Data\RavenDb",
    UseEmbeddedHttpServer = true

}.Initialize();

public static void Initialize()
{
    DocumentStore.Conventions.IdentityPartsSeparator = "-";

    _kernel = new StandardKernel();

    _kernel.Bind<IUserService>().To<UserService>();
    _kernel.Bind<IDocumentStore>().ToConstant(DocumentStore);

    _kernel.Bind<IDocumentSession>().ToMethod(x =>
    {
        var store = x.Kernel.Get<IDocumentStore>();
        return store.OpenSession();
    }).InRequestScope();
}

public static IKernel Kernel
{
    get { return _kernel; }
}

}

スコープを に設定してみましたInSingeltonScope。そのシナリオでは、確かに同じIDocumentSession結果が得られますが、もちろんそれは私が望むものではありません。ここで私が間違っているかもしれないことについて何か提案はありますか?

4

1 に答える 1

2

InRequestScope には、Web 拡張機能の 1 つが必要です。あなたの場合、独自の Bootstrapper の代わりに Ninject.MVC3 をインストールして使用する必要があります。

于 2012-05-19T23:15:51.750 に答える