Hi all,

I'd like to inject SLF4J Logger with Guice, but I have some problem. 
Seeing https://code.google.com/p/google-guice/wiki/CustomInjections I have 
written my TypeListener and my MembersInjector, but all works well only for 
object that are instantiated from Guice.

I mean, if the object that require logger injection is directly create by 
Guice then Guice correctly use mine TypeListener ad MembersInjection to 
inject the instance.
Else (:D) if the object only use Guice but for I provide my own code to 
instantiate it, Guice skips the injection of the logger instance.

What I've seen is that Guice only take care of Class that are binded in 
some Module or that declare some @inject annotation, but in my case not all 
class are managed by Guice.
I'm integrating Guice into App Engine applications that uses Jersey to 
implement REST WS. All my controller are instantiated by Jersey and not by 
Guice, so in those classes my custom injection doesn't work.
Here it is my code:

*public class* JerseyGuiceServletContextListener *extends* 
GuiceServletContextListener 
{

@Override
*protected* Injector getInjector() {
List<AbstractModule> moduleList;
               * //do some classpath scanning to find modules an add all to 
moduleList;*
moduleList.add(new GuiceJerseryServletModule());
*return* Guice.createInjector(moduleList);
}

*private* *class* GuiceJerseryServletModule *extends* JerseyServletModule {
@Override
*protected* *void* configureServlets() {
*final* Map<String, String> parametersMap =
                                                        *new* 
ImmutableMap.Builder<String, 
String>()
*//put some Jersey config parameters*
.build();
*this*.serveRegex(JERSEY_BASE_PATH).with(GuiceContainer.class, 
parametersMap);
}
}
}

So now all my controllers aren't create by Guice but by Jersey, so if I ask 
for Logger injection (with my custom annotation) into one of my controller, 
Guice doesn't inject it. If I explicit bind my controller into 
GuiceJerseryServletModule (with *this*.bind(MyController.class)) Guice 
inject the Logger.
Instead, if I use standard Logger injection, that use java.util.Logger 
class and using @Inject annotation, even if my controller are instantiated 
by Jersey, all works well.

So, there's a way to inject a logger (different from java.util.Logger) even 
if Guice doesn't take care of object creation?
I mean, I know that I could simply bind Logger class, using Providers... 
But in that manner I can't assign the correct name to the Logger...

So I would like to:
1) Inject SLF4J Logger into object that aren't instantiated by Guice
2) Inject a Logger instance that have the correct name.

Thanks to all!

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to