No you don't need the binding if A is concrete. Read: http://code.google.com/p/google-guice/wiki/JustInTimeBindings
2011/4/29 garey <[email protected]> > Thanks Christian. I'll try injecting a Provider since I don't always > want an A. > > To do this, must I have a binding? Since A does not have an > implementation, I put > > bind(A.class).to(A.class); > > in one of my modules, but I don't know if that is necessary or > correct, and it looks a bit silly. > > Garey > > On Apr 29, 3:13 pm, Christian <[email protected]> wrote: > > You can't inject variables that are local to a method body. You'll need > to > > grab field references to A (or Provider<A>) during the servlet's > > construction. > > > > 2011/4/29 garey <[email protected]> > > > > > > > > > > > > > > > > > Hi - > > > > > I have a class that needs a database connection, so I have > > > provides method in a module and I have a constructor like this > > > > > class A { > > > > > @Inject > > > A(Connection c) { ...} > > > > > ... > > > } > > > > > now I have an init method in a servlet that I call if I want to > > > initialize an A. The method requires some parameters, so I do > > > > > public void init( <parameters>) { > > > @Inject A a; > > > > > ... > > > } > > > > > but I get a compile time error telling me that I cannot use @Inject in > > > this way. What fundamental concept am I not getting (this time)? > > > > > Thanks for any help; > > > > > Garey Mills > > > > > -- > > > 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. > > -- > 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. > > -- 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.
