The IDocumentSession in RavenDb should be registered per lifetime scope while the DocumentStore should be resisted as a single instance in Autofac. It's my third time that I'm making a big mistake about the registering of dependencies in autofac! Although it's not a production code and it was just a sort of practice for me.
class DependencyRegistery { public static void Register() { var builder = new ContainerBuilder(); builder.Register(x => { var store = new DocumentStore(); store.Initialize(); return store; }).As<IDocumentStore>().SingleInstance(); builder.Register(x => x.Resolve<IDocumentStore>().OpenSession()) .As<IDocumentSession>() .InstancePerLifetimeScope(); } }