using RavenDB with ServiceStack

前端 未结 4 1066
梦毁少年i
梦毁少年i 2021-02-06 13:14

I read this post by Phillip Haydon about how to use NHibernate/RavenDB with ServiceStack.
I don\'t see the point about getting the IDocumentStore and open new session every

4条回答
  •  误落风尘
    2021-02-06 13:56

    I just included this on the Configure method for the AppHost

    var store = new DocumentStore()
    {
        Url = "http://127.0.0.1:8080",
        DefaultDatabase = "Test"
    }.Initialize();
    
    container.Register(store);
    
    container.Register(c => c.Resolve().OpenSession()).ReusedWithin(ReuseScope.Request);
    

    You can put it aside on module and initialize it.

    Then in your services just add a constructor that accepts IDocumentSession

    public HelloService : Service {
        private readonly IDocumentSession session;
        public HelloService(IDocumentSession session) {
            this.session = session;
        }
    }
    

    And you're good to go.

提交回复
热议问题