ServiceStack NHibernate Session per request

后端 未结 3 576
名媛妹妹
名媛妹妹 2021-01-12 05:01

I am starting to build an app, and I\'m planning to use ServiceStack. Just want to know what are the best practices/good approaches for handling NHibernate ISession or, othe

3条回答
  •  不知归路
    2021-01-12 05:43

    See this blog post for a complete example of how to optimally use ServiceStack and NHibernate together:

    http://www.philliphaydon.com/2012/06/using-nhibernate-with-servicestack/ Here's the AppHost example used in the above post:

    public class Global : HttpApplication
    {
        public class SampleServiceAppHost : AppHostBase
        {
            private readonly IContainerAdapter _containerAdapter;
            public SampleServiceAppHost(ISessionFactory sessionFactory)
                : base("Service Stack with Fluent NHibernate Sample", typeof(ProductFindService).Assembly)
            {
                base.Container.Register(sessionFactory);
            }
    
            public override void Configure(Funq.Container container)
            {
                container.Adapter = _containerAdapter;
            }
        }
    
        void Application_Start(object sender, EventArgs e)
        {
            var factory = new SessionFactoryManager().CreateSessionFactory();
    
            (new SampleServiceAppHost(factory)).Init();
        }
    }
    

提交回复
热议问题