Ohh Man,

Why do I reinvent the wheel!
I also made my ServiceLocator pluggable to any IoCs.

Anoe feature I like in MY ServiceLocator is that I have Substitute method on
the interface that I can use like this:
using (ServiceLocator.Substitute<IDateTimeService>(new
StaticDateTime(currentTime)) {
  // Test whatever needed
} // Here the original IDateTimeService is restored
I'll lokk into the link you gave, maybe it has something similar too.
2009/8/4 Fabio Maulo <[email protected]>

> This is what you should use http://www.codeplex.com/CommonServiceLocator
>
>  <http://www.codeplex.com/CommonServiceLocator>As you can see it has
> adapters for various IoC
>
> 2009/8/3 Dmitiry Nagirnyak <[email protected]>
>
>  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
>>>
>>>
>>
>>
>>
>
>
> --
> 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