I understand how I could perform member injection to achieve my desired 
result.  However, I'd prefer to use only constructor injection.  If I could 
use constructor injection, then the constructor could be used with our 
without Guice. 

One idea is to rewrite the fields of the annotations of constructor 
parameters.  In the example below, x.y.z.Foo's constructor would be 
rewritten* by a Guice listener* of some sort as:

       package x.y.z
       Foo ( @Settings("param1") String x )

or better yet:

       Foo( @Settings String param1 )

is rewritten as:

       package x.y.z
       Foo ( @Settings("x.y.z.Foo.param1") String param1 )

Then, I could use the equivalent of the Named facility to inject a value 
for x.  Is this possible?


On Tuesday, February 7, 2012 12:08:27 AM UTC-8, igor.petrouk wrote:
>
> Hi.
>
> Take a look at TypeListener and MembersInjector. There is an example on 
> how to do custom logging injection.
>
> 2012/2/3 Derrick <[email protected] <javascript:>>
>
>> I would like to inject values dependent on the class they are being 
>> injected into:
>>
>> package x.y.z
>>
>> public class Foo {
>>      @Inject
>>        Foo ( @Settings("param1") String x ) {
>>        }
>> } 
>>
>> where @Settings("param1")  is automatically (effectively) rewritten as 
>> @Named("x.y.z.Foo.param1") in this context and rewritten as 
>> @Named("a.b.c.Bar.param1") 
>> in the following content:
>>
>> package a.b.c
>>
>> public class Bar {
>>      @Inject
>>        Bar ( @Settings("param1") String x ) {
>>        }
>> } 
>>
>> Can I accomplish this with Guice 3.0?  with Guice 4.0 trunk?  as an 
>> extension to Guice 4.0?
>>
>> Thanks!
>>  
>>
>> -- 
>> 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/-/5lY8_VvUONoJ.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> To unsubscribe from this group, send email to 
>> [email protected] <javascript:>.
>> 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/-/5kkiiso8CAgJ.
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