Gili Tzabari
unread,Jan 23, 2012, 10:32:03 AM1/23/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-guice
Hi,
I'm having problems injecting @Named variables inside the request
scope. Removing @Named or attempting to resolve those same variables
in the global scope works fine.
When I attempt to inject the following class:
@RequestScoped
private static class GetModule implements Callable<Module>
{
private final String name;
private final Session session;
@Inject
public GetModule(@Named("name") String name, Session session)
[...]
using:
Map<Key<?>, Object> seedMap = ImmutableMap.<Key<?>,
Object>builder().
put(Key.get(String.class, Names.named("name")), name).build();
return ServletScopes.scopeRequest(new InjectingCallable<>(injector,
GetModule.class),
seedMap).call();
Where "InjectingCallable.call()" invokes
"Injector.getInstance(GetModule.class).call()" inside the REQUEST
scope.
I get this error:
1) No implementation for java.lang.String annotated with
@com.google.inject.name.Named(value=name) was bound.
while locating java.lang.String annotated with
@com.google.inject.name.Named(value=name)
However, if I drop the @Named annotation everything works. I tracked
this down to InjectorImpl:831 that throws an error if an annotated
binding cannot be resolved in the UNSCOPED scope. Why does it throw
this exception? Shouldn't be able to resolve @Named variables in the
request scope? Is this a bug?
Thanks,
Gili