Thanks, locking did it!
On Wed, Feb 17, 2010 at 11:11 AM, Paul Batum <paul.ba...@gmail.com> wrote: > This isn't threadsafe: > > public ISessionFactory SessionFactory > { > get { return this.sessionFactory ?? (this.sessionFactory = > this.ConfigurationGenerator.Generate().BuildSessionFactory()); } > } > > I suggest you take a look at how sharp architecture does it: > > http://github.com/paulbatum/Sharp-Architecture/blob/master/src/SharpArch/SharpArch.Data/NHibernate/NHibernateInitializer.cs > > > On Wed, Feb 17, 2010 at 8:03 PM, Schlaefisch > <schlaefi...@googlemail.com>wrote: > >> We have a WebSessionManager implemented as singleton which creates the >> sessionfactory, using fluent configuration, as needed. >> >> Here is the relevant code: >> >> public class WebSessionManager : ISessionManager >> { >> private static WebSessionManager sessionManager; >> private ISessionFactory sessionFactory; >> private IConfigurationGenerator configurationGenerator; >> >> public static WebSessionManager Instance >> { >> get { return sessionManager ?? (sessionManager = new >> WebSessionManager()); } >> } >> public ISession Session >> { >> get >> { >> if (! >> ManagedWebSessionContext.HasBind(HttpContext.Current, >> this.SessionFactory)) >> { >> ManagedWebSessionContext.Bind(HttpContext.Current, >> this.SessionFactory.OpenSession()); >> } >> return >> this.SessionFactory.GetCurrentSession(); >> } >> } >> public ISessionFactory SessionFactory >> { >> get { return this.sessionFactory ?? (this.sessionFactory = >> this.ConfigurationGenerator.Generate().BuildSessionFactory()); } >> } >> } >> >> public class ConfigurationGenerator : IConfigurationGenerator >> { >> private readonly string connectionString; >> private readonly string sessionContext; // Here: "managed_web" >> >> public FluentConfiguration Generate() >> { >> FluentConfiguration config = Fluently.Configure() >> >> .Database(MsSqlConfiguration.MsSql2005.ConnectionString(this.connectionString) >> .ShowSql().CurrentSessionContext(this.sessionContext)) >> .Mappings(m => >> m.FluentMappings.AddFromAssemblyOf<IConfigurationGenerator>()); >> return config; >> } >> } >> >> >> On Feb 16, 4:58 pm, James Gregory <jagregory....@gmail.com> wrote: >> > Where and how are you creating your session factory? >> > >> > On Tue, Feb 16, 2010 at 3:06 PM, Schlaefisch < >> schlaefi...@googlemail.com>wrote: >> > >> > > Hi, >> > >> > > we're using fluent NHibernate within a SharePoint 2007 WebPart. >> > > Everything works fine except for one problem: >> > >> > > If we reset the web server and 2 (or more) users try to browse the >> > > WebPart, the session factory is created twice at the same time, >> > > resulting in a null reference exception. >> > >> > > Is there any standard approach to prevent this? >> > >> > > -- >> > > You received this message because you are subscribed to the Google >> Groups >> > > "Fluent NHibernate" group. >> > > To post to this group, send email to >> fluent-nhibern...@googlegroups.com. >> > > To unsubscribe from this group, send email to >> > > fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2bunsubscr...@googlegroups.com> >> <fluent-nhibernate%2bunsubscr...@googlegroups.com<fluent-nhibernate%252bunsubscr...@googlegroups.com> >> > >> > > . >> > > For more options, visit this group at >> > >http://groups.google.com/group/fluent-nhibernate?hl=en. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Fluent NHibernate" group. >> To post to this group, send email to fluent-nhibern...@googlegroups.com. >> To unsubscribe from this group, send email to >> fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/fluent-nhibernate?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Fluent NHibernate" group. > To post to this group, send email to fluent-nhibern...@googlegroups.com. > To unsubscribe from this group, send email to > fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/fluent-nhibernate?hl=en. > -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to fluent-nhibern...@googlegroups.com. To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.