Sorry about that, pesky iPhone! On Friday, August 14, 2009, Nicholas Clare <[email protected]> wrote: > On Friday, August 14, 2009, Gili <[email protected]> wrote: >> >> I filed a RFE for injection context: >> http://code.google.com/p/google-guice/issues/detail?id=412 >> >> Gili >> >> On Jul 25, 1:17 pm, Adrian Cole <[email protected]> wrote: >>> Indeed you are correct. I believe this is the only way to accomplish >>> the goal with the current version of guice without hacking core >>> classes. I don't think this was possible at all in Guice 1.0. >>> >>> For this to be accomplished natively, one way could be to add a >>> context to providers. In this context, one could reach the injectee >>> like below: >>> >>> @Provider Logger providerLogger(InjectionContext context){ >>> return Logger.getLogger(context.getInjectee().getClass().getName()); >>> >>> } >>> >>> I'm interested in other opinions on how to accomplish this. >>> >>> Regards, >>> -Adrian >>> jclouds >>> >>> On Sat, Jul 25, 2009 at 4:51 PM, Gili Tzabari<[email protected]> wrote: >>> >>> > Hi Adrian, >>> >>> > If I understand your code directly, you always inject >>> > Logger.getRootLogger() into the constructor, then use reflection to >>> > alter the field after-the-fact to the current type. Is this correct? >>> >>> > I'm looking for a way to set the Constructor argument to the right >>> > value in the first place, instead of fixing it after the fact. It seems >>> > to me that Guice 2.0 is missing a facility for this sort of thing. Are >>> > there any plans for adding one in Guice 2.1 or 3.0? >>> >>> > Thanks, >>> > Gili >>> >>> > Adrian Cole wrote: >>> >> Hi, Gili. >>> >>> >> I've just coded this for you.. I hope you digg it ;) >>> >>> >>http://digg.com/d3yXEh >>> >>> >> Cheers, >>> >> -Adrian >>> >> jclouds >>> >>> >> On Fri, Jul 24, 2009 at 2:22 PM, Gili Tzabari<[email protected]> >>> >> wrote: >>> >>> Guys, >>> >>> >>> I don't understand your answers. It sounds to me like you're >>> >>> talking >>> >>> about field injection, not constructor injection. >>> >>> >>> I don't want to inject a log into an already-constructed object. >>> >>> I want >>> >>> to inject a log directly into the class constructor: >>> >>> >>> class Foo >>> >>> { >>> >>> private final Logger log; >>> >>> >>> @Inject >>> >>> public Foo(Logger log) >>> >>> { >>> >>> this.log = log; >>> >>> } >>> >>> } >>> >>> >>> Also, I am not necessarily doing this for jdk loggers so please >>> >>> provide >>> >>> more detail on how to write a custom injection listener to do this. >>> >>> >>> Thanks, >>> >>> Gili >>> >>> >>> Adrian Cole wrote: >>> >>>> If just injecting a log class, you're right: that's trivial. The >>> >>>> less trivial part is setting the log scope relevant to the object >>> >>>> being constructed. >>> >>> >>>> -Adrian >>> >>> >>>> On Fri, Jul 24, 2009 at 10:51 AM, Dhanji R. Prasanna<[email protected]> >>> >>>> wrote: >>> >>>>> You can also write a trivial injection listener that looks for >>> >>>>> whatever >>> >>>>> logging class you like and set it after construction. >>> >>>>> Dhanji. >>> >>> >>
--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
