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
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();
}
}