【问题标题】:ASP.NET MVC 4 and Ninject InRequestScope with RavenDb IDocumentSession in embedded HttpServer modeASP.NET MVC 4 和 Ninject InRequestScope 与 RavenDb IDocumentSession 在嵌入式 HttpServer 模式
【发布时间】:2012-05-20 07:15:51
【问题描述】:

我在使用 Ninject 的 InRequestScope 扩展时遇到了一些问题。看起来我在同一个请求中获得了 IDocumentSession 的新实例。我使用 ASP.NET MVC 4 beta 将 RavenDb 作为嵌入式 HttpServer 运行。我有一个如下所示的引导程序类:

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,但这当然不是我想要的。关于我在这里可能做错的任何建议?

【问题讨论】:

    标签: ninject ravendb asp.net-mvc-4


    【解决方案1】:

    InRequestScope 需要其中一种 Web 扩展。在您的情况下,您应该安装和使用 Ninject.MVC3 而不是自己的引导程序。

    【讨论】:

      猜你喜欢
      • 2011-05-28
      • 1970-01-01
      • 2023-03-08
      • 2020-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多