I use ServiceLocator in such cases: http://martinfowler.com/articles/injection.html#UsingAServiceLocator
Yes, basically it is needed to have some statics. But it doesn't mean that ISession/ISessoinFactory should be stored static variables. What I do is: 1) ServiceLocator provides interface accessible via static property. 2) The instance of that interface (implementation) is stored via another interface called Store. 3) I have different kinds of store: ThreadStatic, Static, PerRequest. 4) I implement ServiceLocator as a facade over the WindsorContainer, so it is easy to resolve dependencies on it as well. Anyway, there's MS implementation available if you like: http://msdn.microsoft.com/en-us/library/cc707905.aspx Cheers, Dmitriy. 2009/8/4 Fabio Maulo <[email protected]> > Dependency Injection > > 2009/8/3 rg <[email protected]> > > >> Thanks Fabio, naturally there's next question: you can get current >> contextual session by calling ISessionFactory.GetCurrentSession(), but >> how do you get current ISessionFactory? Do I still have to implement >> some public static field with ISessionFactory, or is it also somehow >> built into NHibernate? >> Rafal >> >> On Aug 3, 3:50 pm, Fabio Maulo <[email protected]> wrote: >> > http://nhforge.org/doc/nh/en/index.html#architecture-current-session >> > >> > 2009/8/3 rg <[email protected]> >> > >> > >> > >> > >> > >> > >> > >> > > Hi, I'd like to add some logic to my data objects by implementing >> > > additional methods. However, these methods have to access current >> > > ISession to be able to load or update any data. I could pass the >> > > ISession as a parameter to each method, but this is unacceptable for >> > > some reasons. It would be better if current session was stored >> > > somewhere where it can be publicly accessed - for example in thread >> > > local storage, so it can be retrieved by all methods executed in >> > > current thread. >> > > Passing ISession to each method is unacceptable because I want to call >> > > these methods using Ajax-RPC and certainly don't want to deal with >> > > ISession parameter client side (NH session is managed externally by >> > > RPC controller). Of course I can go with thread local storage, but >> > > maybe you have better ideas. >> > > Best regards >> > > Rafal >> > >> > -- >> > Fabio Maulo >> >> > > > -- > 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 -~----------~----~----~----~------~----~------~--~---
