Hi Scott,

Thank you for you're reply.  I haven't been able to figure this out.

I get the request scope approach.  I was thinking in terms of the session 
scope, but request would be less like setting global variables to be picked 
up.

In the second solution, given a chain like D(C(B(A))) do you mean:

Call 'D.input(value);'  which in turn calls 'C.input(value)' all the way up 
to A where it is needed.

I know that is generally bad practice, but is it more or less required here 
if making a Request scope global object is undesirable?

Thank,
Casey



On Monday, April 1, 2013 9:59:11 PM UTC-7, scott wrote:
>
>
> I'm not completely following your code example, but I think I have a basic 
> understanding of your problem and I think I may have had similar issues in 
> the past. You have an input parameter you want to pass down through your 
> call chain, and you have an output you want to return back up your call 
> chain. I don't think Guice really makes this anymore difficult, and it may 
> have some things you can leverage to make it easier.
>
> How would you go about doing this if you weren't using Guice? If you're 
> wanting to pass parameters to objects via their constructor, well you are 
> delegating to Guice and your Guice modules to construct your object graph 
> so your options are slightly limited. If you are in the context of 
> receiving an HTTP request, you could use a @RequestScoped variable to store 
> the data, then access the @RequestScoped variable to construct the leaf 
> object. If you are not in the context of an HTTP request, but all the calls 
> are happening in the same thread, then you could use a ThreadLocal variable 
> to store the data. Or you could get fancy and implement a CustomScope, 
> although this is generally not recommended and you would likely need to 
> leverage ThreadLocal or some global/static mechanism to make it work 
> anyway. In any of these cases, you will likely need to delay the creation 
> of your leaf object until you've had a chance to set the input data (in 
> RequestScoped or ThreadLocal), you can do this by using a Guice Provider to 
> get an instance of the leaf object, then just make sure you call the 
> Provider sometime after the input data has been set.
>
> Another (maybe too obvious?) solution, would be to just pass the input 
> parameter via a typical method invocation, and return the output through 
> the return. Is there a reason why you can't do that? You can separate 
> constructing your system from using it by using Guice to construct your 
> object graph, but then calling methods with parameters and return values to 
> pass values up and down the call stack.
>
>
>
> On Saturday, March 30, 2013 11:21:36 AM UTC-5, caseybasichis wrote:
>>
>> Hi.
>>
>> So i realize this is a kind of circular dependency.
>>
>> How do you all go about taking a serial DI chain that takes an input and 
>> output?
>>
>> The only method i've been able to come up with is sticking a session 
>> scope object at the top of each chain so I can pass it a global value as an 
>> input for it to send down the chain.  This seems like an awful practice.
>>
>> On Thursday, March 28, 2013 8:19:46 AM UTC-7, caseybasichis wrote:
>>>
>>> Hi,
>>>
>>> class E {
>>> public:
>>>    E(D);
>>>    setLeafData(AData);
>>>    getE();
>>> };
>>>
>>> class D {
>>> public:
>>>    D(C)
>>> ..
>>>
>>> class A {
>>> public:
>>>    A();   
>>>    setAData(AData)
>>>    getAData()
>>> }
>>>
>>> myE = inject->E
>>>
>>> myE.setLeafData("blah")
>>> myE.getE();
>>>
>>> Here is a basic idea.  It's not Java, but the concept is a fundamental 
>>> question.
>>>
>>> On Thursday, March 28, 2013 7:52:05 AM UTC-7, Fred Faber wrote:
>>>>
>>>> Could you sketch a quick concrete example to show this in code real 
>>>> quick?
>>>>
>>>> On Thu, Mar 28, 2013 at 10:29 AM, caseybasichis <[email protected]>wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I am struggling to understand how to give parameter information to 
>>>>> leaf nodes, from the root node in a DI setup similar to Guice.
>>>>>
>>>>> I have a class that takes a set of A's and generates E's. 
>>>>>  (E(D(C(B(A)))))
>>>>>
>>>>> E is the injected, the rest are instantiated by the DI, A is an 'A 
>>>>> provider' or 'A factory'
>>>>>
>>>>> E is the interface, how can I get a path, or other const data from a 
>>>>> function in E to A, to start the function chain?
>>>>>
>>>>> In other words I have some simple data A, that gets processed through 
>>>>> a function chain, down to an E class which generates an E_Data object 
>>>>> which 
>>>>> is then used in the root of my application.
>>>>>
>>>>> Do I string functions through E,D,C,B to get A's reference? That seems 
>>>>> wrong.
>>>>>
>>>>> Reversing the chain make the path simple A(B(C(D(E))))), but the only 
>>>>> way to get the output seems to be to attach a singleton to E like 
>>>>> A(B(C(D(E(SQL)))))).
>>>>>
>>>>> That seems like inversion-of-inversion of control, but it also seems 
>>>>> like a data manager could be made at the session scope that E could take 
>>>>> as 
>>>>> a constructor.
>>>>>
>>>>> What do I have flipped?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Casey
>>>>>
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "google-guice" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> Visit this group at http://groups.google.com/group/google-guice?hl=en.
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>  
>>>>>  
>>>>>
>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to