Ehsan Ghanbari

Experience, DotNet, Solutions

Register the store and session of RavenDb with Autofac

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();
                return store;

            builder.Register(x => x.Resolve<IDocumentStore>().OpenSession())


About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
Peridic pattern
How to query over Icollection<> of a type with linq
How to use PagedList In MVC
Domain driven design VS model driven architecture
What's the DDD-lite?
Using Generic type for type casting in F#