I am running into a few problems when taking this approach.  Namely, you 
can not get annotation data from parameters when the function is 
transformed into a Function2 object.  This means I can't inject anything 
with the Named annotation.

On Monday, October 8, 2012 9:50:49 AM UTC-6, Travis Stevens wrote:
>
> I currently do inject the validator and process into the class, but I 
> don't like that approach.  What ends up happening is that there are a lot 
> of methods in some of our classes and then there are a lot of dependencies 
> that are injected into each instance.  For any particular method call, the 
> method uses only a subset of the dependencies that are injected into the 
> instance so there becomes no clear relationship between a method call and 
> it's dependencies.
>
> I have started currying the methods and it feels a lot cleaner and 
> clearer, actually, and gives me a better idea of what may need refactoring 
> if it takes too many dependencies.
>
> Anyway, I was able to get a proof of concept for a Function2 injection: 
> https://github.com/OleTraveler/Gin-and-Guice/blob/master/src/test/scala/com/ot/gin/GinSpec.scala
>
> -Trav
>
> On Friday, October 5, 2012 11:01:44 PM UTC-6, Thomas Suckow wrote:
>>
>> I think you should inject the validator and processor into the class that 
>> contains computevalue. I also recommend looking at scala-guice. If you do 
>> find another way, I would love to hear it or add it to scala-guice.
>> On Oct 5, 2012 10:53 AM, "Travis Stevens" <[email protected]> wrote:
>>
>>> I have an idea to use Guice to inject objects into scala curried 
>>> functions.  For example, suppose I have the method signature:
>>>
>>> def computeValue(x: String)(validator: Validator, processor: Processor): 
>>>> Answer
>>>
>>>
>>> And Guice knows how to build the Validator  
>>>
>>>>  binder.bind(classOf[Validator]).toInstance(new MyValidator())
>>>
>>>
>>> If I call computeValue("value") I am left with a scala object which is a 
>>> Function2[Validator, Processor, Answer], meaning I do something like:
>>>
>>> injector: Injector = ....
>>>> val v = injector.getInstance(classOf[Validation])
>>>> va p = injectory.getInstance(classOf[Processor])
>>>> f2.apply(v,p)
>>>
>>>
>>> Is there a way that I can simplify this process and make it more generic 
>>> by using the Function2 type signature in order to get the values and call 
>>> f2.apply?
>>>
>>> thanks,
>>> -Trav
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "google-guice" group.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msg/google-guice/-/XjWjv94WFGcJ.
>>> 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 view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/VWYSgfLeUlAJ.
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