using RavenDB with ServiceStack

前端 未结 4 1074
梦毁少年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:55

    Filtering the response in ServiceStack

    The ways to introspect the Response in ServiceStack is with either:

    • The Response Filter or Response Filter Attributes or other custom hooks
    • Overriding AppHost.ServiceExceptionHandler or custom OnAfterExecute() hook

    Some other notes that might be helpful:

    ServiceStack's built-in IOC (Funq) now supports RequestScope

    You can add IDisposable to a base class which gets called immediately after the service has finished executing, e.g. if you were to use an RDBMS:

    public class FooServiceBase : IService, IDisposable
    {
        public IDbConnectionFactory DbFactory { get; set; }
    
        private IDbConnection db;
        public IDbConnection Db
        {
            get { return db ?? (db = DbFactory.OpenDbConnection()); }
        }
    
        public object Any(ProductFind request)
        {
            return new FooResponse {
                Result = Db.Id(request.Id)
            };
        }
    
        public void Dispose()
        {
            if (db != null) db.Dispose();
        }
    }
    

提交回复
热议问题