You assumed correct.

Could you show some pseudo code? Im a bit unsure of how I should use
threadlocal.. You can scope a provider, providing you have a scope for it. I
don't think a static container would work since, since instances of
SpecialObject are request specific..

Thanks for your help so far, interesting point with threadlocal.

regards Nino

2009/11/24 Brian Pontarelli <[email protected]>

> I'd assume something else is instantiating "myclass" and you need to inject
> it by hand. In this case, you have a couple of options:
>
> - ThreadLocal
> - Singleton/static container
>
> I don't think Providers are scoped (I could be wrong on that) and therefore
> you can't get the Provider from the injector and then set the value into the
> provider. Using a ThreadLocal could work if it is safe to assume you are in
> a single thread. Otherwise, you might have to do some fancy foot work with a
> singleton or static container to hold the SpecialObject until the Provider
> can grab it.
>
> -bp
>
>
> On Nov 24, 2009, at 5:29 AM, nino martinez wael wrote:
>
> I know about providers and we are using them alot.
>
> However I fail to see how I can tell a provider to use a specific instance
> only for that request. Should the pseudo code be something like this:
>
>
> public myclass(SpecialObject specialObject )
> {
> --->provider.setInstance(SpecialObject);
> InjectorCreator.InjectMembers(
> this);
> }
>
> How would I get the provider? And how would I makes sure it were only in
> the current request so we don't get mixed instances over requests..?
>
> regards Nino
>
>
>
> 2009/11/24 Anton Gavazuk <[email protected]>
>
>> you can use a Provider and it will take care creating/getting required
>> instance for injection.
>>
>> 2009/11/24 nino martinez wael <[email protected]>
>>
>>> Hi
>>>
>>> A couple days ago I wrote to the forum, but I don't think my mail came
>>> through.
>>>
>>> I have a case where only the code that needs injection can provide one of
>>> the objects that needs to be injected :(
>>>
>>> The code looks something like this:
>>>
>>> Myclass
>>>
>>> public myclass(SpecialObject specialObject )
>>> {
>>> --->
>>> InjectorCreator.InjectMembers(this);
>>> }
>>>
>>> @inject
>>> public void setController(Controller controller){
>>>
>>> }
>>>
>>> And lastly the controller class:
>>>
>>> Controller{
>>>
>>> @inject
>>> public void setSpecialObject(SpecialObject specialObject ){
>>>
>>> }
>>>
>>> .. @inject a lot of other stuff too
>>>
>>> }
>>>
>>> So my question are can I somehow make Guice aware of the SpecialObject
>>> instance at the ---> marker?
>>>
>>> Further the instance reference has to be requestscoped or at least only
>>> use the specified instance for the current request only, myclass will only
>>> be instantiated once per request .
>>>
>>> Regards Nino
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "google-guice" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<google-guice%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/google-guice?hl=en.
>>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "google-guice" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<google-guice%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-guice?hl=en.
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" 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/google-guice?hl=en.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-guice%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>

--

You received this message because you are subscribed to the Google Groups 
"google-guice" 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/google-guice?hl=en.


Reply via email to