ravendb, касл МоК, объект Wcf - стиль изложения сессии doc

StackOverflow https://stackoverflow.com/questions/5310397

Вопрос

Каков рекомендуемый образ жизни для сеанса raven doc и хранилища в windsor ioc, wcf facility setup, размещенных в IIS?

Я продолжаю видеть эту ошибку:

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);

        }
    }
Это было полезно?

Решение

Этот же вопрос о жизненном цикле был поднят на форумах Raven:https://groups.google.com/forum /#!тема/ravendb/wUgULf3eoCg

Ответ Айенде был таким:Синглтон для хранилища документов, Временный / веб-запрос для сеанса.

Другие советы

Я решил эту проблему, поступив следующим образом:

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"
            });
    }
}

Это работает как заклинание!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top