ravendb、castle IoC、Wcf 设施 - 文档会话 liefstyle

发布于 2024-10-23 11:55:56 字数 1783 浏览 2 评论 0原文

在 IIS 中托管的温莎 ioc、wcf 设施设置下,raven 文档会话和存储的推荐生活方式是什么?

我不断看到此错误:

Error TempPathInUse (JET_errTempPathInUse, Temp path already used by another database instance)`

这是我的设置:

public class RavenInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(
                Component.For<IDocumentStore>().ImplementedBy<DocumentStore>()
                    .DependsOn(new { connectionStringName = "RavenConnectionString" })
                    .OnCreate(DoInitialisation)
                    .LifeStyle.Singleton,
                Component.For<IDocumentSession>()
                    .UsingFactoryMethod(GetDocumentSesssion)
                    .LifeStyle.Transient
                );

            container.Register(Component.For<IEventSeriesRepository>().ImplementedBy<EventSeriesRepository>().LifeStyle.Transient);
            container.Register(Component.For<IEventInstanceRepository>().ImplementedBy<EventInstanceRepository>().LifeStyle.Transient);
            container.Register(
                Component.For<IProductionCompanyRepository>().ImplementedBy<ProductionCompanyRepository>().LifeStyle.
                    Transient);
        }

        static IDocumentSession GetDocumentSesssion(IKernel kernel)
        {
            var store = kernel.Resolve<IDocumentStore>();
            return store.OpenSession();
        }

        public static void DoInitialisation(IKernel kernel, IDocumentStore store)
        {
            store.Initialize();
            IndexCreation.CreateIndexes(typeof(EventSeries_ByName).Assembly, store);

        }
    }

What's the recommended lifestyle for raven doc session and store under a windsor ioc, wcf facility setup hosted in IIS?

I keep seeing this error:

Error TempPathInUse (JET_errTempPathInUse, Temp path already used by another database instance)`

here is my setup:

public class RavenInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(
                Component.For<IDocumentStore>().ImplementedBy<DocumentStore>()
                    .DependsOn(new { connectionStringName = "RavenConnectionString" })
                    .OnCreate(DoInitialisation)
                    .LifeStyle.Singleton,
                Component.For<IDocumentSession>()
                    .UsingFactoryMethod(GetDocumentSesssion)
                    .LifeStyle.Transient
                );

            container.Register(Component.For<IEventSeriesRepository>().ImplementedBy<EventSeriesRepository>().LifeStyle.Transient);
            container.Register(Component.For<IEventInstanceRepository>().ImplementedBy<EventInstanceRepository>().LifeStyle.Transient);
            container.Register(
                Component.For<IProductionCompanyRepository>().ImplementedBy<ProductionCompanyRepository>().LifeStyle.
                    Transient);
        }

        static IDocumentSession GetDocumentSesssion(IKernel kernel)
        {
            var store = kernel.Resolve<IDocumentStore>();
            return store.OpenSession();
        }

        public static void DoInitialisation(IKernel kernel, IDocumentStore store)
        {
            store.Initialize();
            IndexCreation.CreateIndexes(typeof(EventSeries_ByName).Assembly, store);

        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

转瞬即逝 2024-10-30 11:55:56

Raven 论坛中也提出了关于生命周期的相同问题:
https://groups.google.com/forum/#!topic/ravendb/wUgULf3eoCg

Ayende 的回应是:
用于文档存储的单例,用于会话的瞬态/Web 请求。

This same question about lifecycle was raised in the Raven forums:
https://groups.google.com/forum/#!topic/ravendb/wUgULf3eoCg

Ayende's response was:
Singleton for the Document Store, Transient / Web Request for the session.

亽野灬性zι浪 2024-10-30 11:55:56

我通过这样做解决了这个问题:

container.Register(
    Component
        .For<IRavenSessionFactoryBuilder>()
        .ImplementedBy<RavenSessionFactoryBuilder>()
        .LifeStyle.Singleton
    );

container.Register(
    Component
        .For<IDocumentSession>()
        .UsingFactoryMethod(kernel => 
            kernel.Resolve<IRavenSessionFactoryBuilder>()
               .GetSessionFactory()
               .CreateSession()
        )
        .LifeStyle.Transient
    );

// This is the repository making use of the IDocumentSession
container.Register(
    Component
        .For<IDomainRepository>()
        .ImplementedBy<DomainRepository>()
        .LifeStyle.Transient
    );

这是 RavenSessionFactoryBuilder

public class RavenSessionFactoryBuilder : IRavenSessionFactoryBuilder
{
    private IRavenSessionFactory ravenSessionFactory;

    public IRavenSessionFactory GetSessionFactory()
    {
        return ravenSessionFactory ?? (ravenSessionFactory = CreateSessionFactory());
    }

    private static IRavenSessionFactory CreateSessionFactory()
    {
        return new RavenSessionFactory(
            new DocumentStore {
                Url = "http://localhost:8080"
            });
    }
}

它的工作方式就像一个魅力!

I solved this by doing like this:

container.Register(
    Component
        .For<IRavenSessionFactoryBuilder>()
        .ImplementedBy<RavenSessionFactoryBuilder>()
        .LifeStyle.Singleton
    );

container.Register(
    Component
        .For<IDocumentSession>()
        .UsingFactoryMethod(kernel => 
            kernel.Resolve<IRavenSessionFactoryBuilder>()
               .GetSessionFactory()
               .CreateSession()
        )
        .LifeStyle.Transient
    );

// This is the repository making use of the IDocumentSession
container.Register(
    Component
        .For<IDomainRepository>()
        .ImplementedBy<DomainRepository>()
        .LifeStyle.Transient
    );

And here is the RavenSessionFactoryBuilder

public class RavenSessionFactoryBuilder : IRavenSessionFactoryBuilder
{
    private IRavenSessionFactory ravenSessionFactory;

    public IRavenSessionFactory GetSessionFactory()
    {
        return ravenSessionFactory ?? (ravenSessionFactory = CreateSessionFactory());
    }

    private static IRavenSessionFactory CreateSessionFactory()
    {
        return new RavenSessionFactory(
            new DocumentStore {
                Url = "http://localhost:8080"
            });
    }
}

It works like a charm!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文