The 'Permanent' SessionFactory, ASP.NET MVC and nHibernate -
i've been building application fluent nhibernate/asp.net mvc - , i've dug around , figured out it's considered appropriate practice keep 'permanent' sessionfactory open, , use sessions each request database. okay, sounds good...
i'm quite confused on how accomplish this, though. find assumes entire structured framework uses kind of ioc container system ...and that's advanced have far. there more simple examples of how implement kind of design?
i've taken @ where can find nhibernate , asp.net mvc reference application
and read book "asp.net mvc in action", it's example far more complicated trying achieve. thought singleton model work in application_start of 'global.asax
' didn't yield results had hoped for. keep disposing of factory , never recreating it.
you expose isessionfactory
singleton:
public sealed class factorymanager { private static readonly isessionfactory _instance = createsessionfactory(); static factorymanager() { } public static isessionfactory instance { { return _instance; } } private static isessionfactory createsessionfactory() { // todo: configure fluentnhibernate , create session factory } }
now use factorymanager.instance
in code:
using (var session = factorymanager.instance.opensession()) using (var tx = session.begintransaction()) { // todo: use session here tx.commit(); }
Comments
Post a Comment