Are you using a IoC container in somewhere ?

2009/2/5 CCL <[email protected]>

>
> Thanks for the feedback!
>
> I now see that the construction we have might not be a pure singleton
> implementation since it does have an Init() function - that is called
> from global.asax. What is missing is perhaps a (SessionFactory ==
> null) check before line 13 so that the object is not recreated even if
> we happen to call Init multiple times... Or even better, change the
> init function to a static constructor for the class.
>
> 1       public static class NHibernateSession
> 2       {
> 3               public static ISessionFactory SessionFactory { get; set; }
> 4               public static ISessionStorage Storage { get; set; }
> 5
> 6               public static void Init(ISessionStorage storage, string
> cfgFile) {
> 7                       Configuration cfg = new Configuration();
> 8                                               if (cfgFile == null)
> 9                               cfg = cfg.Configure();
> 10                      else
> 11                              cfg = cfg.Configure(cfgFile);
> 12
> 13                      SessionFactory = cfg.BuildSessionFactory();
> 14                      Storage = storage;
> 15              }
> 16
> 17              public static ISession Current {
> 18                      get {
> 19                              ISession session = Storage.Session;
> 20                                                      if (session ==
> null) {
> 21                                      session =
> SessionFactory.OpenSession();
> 22                                      Storage.Session = session;
> 23                              }
> 24                                                      return session;
> 25                      }
> 26              }
> 27      }
>
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to