Ich,
Instead of using the injector, you can use a provider. Guice will
inject a provider of the class you need, if you ask it to. For
instance in the following code if your servlet is bound with Guice, a
provider of your GetSomeClass will be injected for you (and you won't
need to write the provider either).
@Singleton
public class SomeServiceImpl extends RemoteServiceServlet implements
SomeService {
private Provider<GetSomeClass> getSomeClassProvider;
@Inject
public SomeServiceImpl(Provider<GetSomeClass> getSomeClassProvider) {
this.getSomeClassProvider= getSomeClassProvider;
}
public ArrayList<> getSome(){
return getSomeClassProvider.get().getSome();
}
On 4 July 2011 07:21, ich du <[email protected]> wrote:
> i don't know if i nee the injecotr but i need an instance of a class (to
> call a method on it). this class has an inject on constructor. all examples
> i saw uses injector to get an instance of the class. some example talk about
> "bootstrapping" - in main method they create an injector (). in servlet case
> the injector is created in "GuiceServletContextListener" - and i guess
> without this injector instance nothing will work. so with this in place on
> first rpc call a injector is created and injection happens.
>
> My problem is how to call a method on an instance if i don't have the
> instance? as i mentioned before i have 2 modules one for servlets and one
> for all other stuff. i need an instance of other stuff. ok here is an
> example:
>
> my RemoteServiceServlet:
>
> ...
> public ArrayList<> getSome(){
> return (some class with inject on constructor).getSome();
> }
>
> at the moment it looks like:
>
> return
> ServerInjector.GET.instance().getInstance(GetSomeClass.class).getSome();
>
> At the moment i have a singleton injector on server side and the method
> above and the Listener use this injector. so how could this work without
> injector - (i thought to inject a dependency via guice i need at least a
> place for injection - an construcot or method with instance as parameter?!)
>
> jhulford - please tell me what you mean with "just inject it into your
> service" - i am a total DI noob
>
> --
> 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/-/vXyhIZZ5OWMJ.
> 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 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.