﻿using Ninject;
using Ninject.Modules;
using Ninject.Web.Common;

using Raven.Client;
using Raven.Client.Embedded;

namespace CGO.Web.NinjectModules
{
    public class RavenModule : NinjectModule
    {
        public override void Load()
        {
            Kernel.Bind<IDocumentStore>().ToMethod(_ => InitialiseDocumentStore()).InSingletonScope();
            Kernel.Bind<IDocumentSession>().ToMethod(_ => Kernel.Get<IDocumentStore>().OpenSession()).InRequestScope();
        }

        private static IDocumentStore InitialiseDocumentStore()
        {
            var documentStore = new EmbeddableDocumentStore
            {
                DataDirectory = "CGO.raven",
                UseEmbeddedHttpServer = true
            };

            documentStore.InitializeProfiling();
            documentStore.Initialize();

            return documentStore;
        }
    }
}
﻿using Ninject;
using Ninject.Modules;
using Ninject.Web.Common;

using Raven.Client;
using Raven.Client.Embedded;

namespace CGO.Web.NinjectModules
{
    public class RavenModule : NinjectModule
    {
        public override void Load()
        {
            Kernel.Bind<IDocumentStore>().ToMethod(_ => InitialiseDocumentStore()).InSingletonScope();
            Kernel.Bind<IDocumentSession>().ToMethod(_ => Kernel.Get<IDocumentStore>().OpenSession()).InRequestScope();
        }

        private static IDocumentStore InitialiseDocumentStore()
        {
            var documentStore = new EmbeddableDocumentStore
            {
                DataDirectory = "CGO.raven",
                UseEmbeddedHttpServer = true,
                Configuration = { Port = 28645 }
            };

            documentStore.InitializeProfiling();
            documentStore.Initialize();

            return documentStore;
        }
    }
}
Fix RavenConfiguration for Embedded mode.
Fix RavenConfiguration for Embedded mode.

Poorly-documented, but there we go: in embedded mode, Raven assumes the
same port number as the web application, which caused no end of issues.
